[SQL-CVS] [ sqlobject-Bugs-2417338 ] _connection ignored if sqlhub.processConnection set before
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: SourceForge.net <no...@so...> - 2009-05-18 16:44:47
|
Bugs item #2417338, was opened at 2008-12-11 18:02 Message generated for change (Settings changed) made by phd You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=2417338&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: General Group: None >Status: Closed >Resolution: Fixed Priority: 5 Private: No Submitted By: Luci Stanescu (luci_stanescu) Assigned to: Oleg Broytmann (phd) Summary: _connection ignored if sqlhub.processConnection set before Initial Comment: If sqlhub.processConnection is set before a subclass of SQLObject is defined, then the _connection attribute of the new class will be ignored. This is, as far as I could find out, because of: sqlobject/main.py:768 if connection and not hasattr(cls, '_connection'): cls.setConnection(connection) This creates a lot of confusion and, if I understood correctly, is not the intended behaviour either (citing from the documentation): "If you have defined sqlhub.processConnection then this attribute can be omitted from your class and the sqlhub will be used instead. If you have several classes using the same connection that might be an advantage, besides saving a lot of typing." ---------------------------------------------------------------------- >Comment By: Oleg Broytmann (phd) Date: 2009-05-18 20:44 Message: ixed in the revisions 3889:3891. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2009-04-29 18:58 Message: The problem is hasattr(cls, '_connection') - even if there is the code del cls._connection a few lines above hasattr(cls, '_connection') return True in your case because there is a connection in SQLObject class. To fix this I propose to replace hasattr(cls, '_connection') with the test '_connection' not in cls.__dict__: @@ -768,7 +768,7 @@ if hasattr(mod, '__connection__'): connection = mod.__connection__ - if connection and not hasattr(cls, '_connection'): + if connection and ('_connection' not in cls.__dict__): cls.setConnection(connection) What do you think? ---------------------------------------------------------------------- Comment By: Luci Stanescu (luci_stanescu) Date: 2008-12-11 18:31 Message: testsqlobject.py: from sqlobject import * a_connection = connectionForURI('mysql://user:pass@other_host/db') sqlhub.processConnection = connectionForURI('mysql://user:pass@host/db') class Foo(SQLObject): _connection = a_connection bar = StringCol(length=16) print Foo._connection.uri() luci@lucifer:~/sandbox$ python testsqlobject.py mysql://user:pass@host/db It was supposed to print `mysql://user:pass@other_host/db', which it does, if I move the line sqlhub.processConnection = connectionForURI('mysql://user:pass@host/db') after the class is defined. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2008-12-11 18:13 Message: if connection and not hasattr(cls, '_connection') means "if there is a global connection and there is no _connection attribute". So I don't see how SQLObject can ignore _connection - there is no one. Can you write a short program that demonstrates the problem? ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=2417338&group_id=74338 |