Author: phd
Date: 2010-02-26 14:27:29 -0700 (Fri, 26 Feb 2010)
New Revision: 4110
Modified:
SQLObject/trunk/docs/News.txt
SQLObject/trunk/sqlobject/main.py
SQLObject/trunk/sqlobject/tests/test_select.py
Log:
Merged revisions 4107, 4108 from branch 0.11: fixed a comment;
do not set _perConnection flag if get() or _init() is passed the same
connection; this is often the case with select().
Modified: SQLObject/trunk/docs/News.txt
===================================================================
--- SQLObject/trunk/docs/News.txt 2010-02-26 21:27:07 UTC (rev 4109)
+++ SQLObject/trunk/docs/News.txt 2010-02-26 21:27:29 UTC (rev 4110)
@@ -97,6 +97,9 @@
connection is not a transaction and is in autocommit mode - remove
parent row(s).
+* Do not set _perConnection flag if get() or _init() is passed the same
+ connection; this is often the case with select().
+
SQLObject 0.11.3
================
Modified: SQLObject/trunk/sqlobject/main.py
===================================================================
--- SQLObject/trunk/sqlobject/main.py 2010-02-26 21:27:07 UTC (rev 4109)
+++ SQLObject/trunk/sqlobject/main.py 2010-02-26 21:27:29 UTC (rev 4110)
@@ -768,7 +768,7 @@
# Do not check hasattr(cls, '_connection') here - it is possible
# SQLObject parent class has a connection attribute that came
- # from sqlhub, e.g.; # check __dict__ only.
+ # from sqlhub, e.g.; check __dict__ only.
if connection and ('_connection' not in cls.__dict__):
cls.setConnection(connection)
@@ -921,7 +921,7 @@
# If no connection was given, we'll inherit the class
# instance variable which should have a _connection
# attribute.
- if connection is not None:
+ if (connection is not None) and (self._connection != connection):
self._connection = connection
# Sometimes we need to know if this instance is
# global or tied to a particular connection.
@@ -1207,9 +1207,10 @@
# Pass the connection object along if we were given one.
if kw.has_key('connection'):
- self._connection = kw['connection']
- self.sqlmeta._perConnection = True
- del kw['connection']
+ connection = kw.pop('connection')
+ if self._connection != connection:
+ self._connection = connection
+ self.sqlmeta._perConnection = True
self._SO_writeLock = threading.Lock()
Modified: SQLObject/trunk/sqlobject/tests/test_select.py
===================================================================
--- SQLObject/trunk/sqlobject/tests/test_select.py 2010-02-26 21:27:07 UTC (rev 4109)
+++ SQLObject/trunk/sqlobject/tests/test_select.py 2010-02-26 21:27:29 UTC (rev 4110)
@@ -189,3 +189,8 @@
setupClass(IterTest)
IterTest(name='sqlobject')
IterTest.select(IterTest.q.name==u'sqlobject')
+
+def test_select_perConnection():
+ setupClass(IterTest)
+ IterTest(name='a')
+ assert not IterTest.select().getOne().sqlmeta._perConnection
|