]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
flush(objects=[]) is a no-op [ticket:928]
authorJason Kirtland <jek@discorporate.us>
Tue, 22 Apr 2008 19:29:56 +0000 (19:29 +0000)
committerJason Kirtland <jek@discorporate.us>
Tue, 22 Apr 2008 19:29:56 +0000 (19:29 +0000)
lib/sqlalchemy/orm/session.py
test/orm/session.py

index b7a4aa911eaf20bc9bda759a07119be28de3039a..076727486e026c1e3f488d69d2aac4fab6576c94 100644 (file)
@@ -750,10 +750,18 @@ class Session(object):
         """Flush all the object modifications present in this session
         to the database.
 
-        `objects` is a list or tuple of objects specifically to be
+        `objects` is a collection or iterator of objects specifically to be
         flushed; if ``None``, all new and modified objects are flushed.
-        """
 
+        """
+        if objects is not None:
+            try:
+                if not len(objects):
+                    return
+            except TypeError:
+                objects = list(objects)
+                if not objects:
+                    return
         self.uow.flush(self, objects)
 
     def get(self, class_, ident, **kwargs):
index e4b42ab1cb9420706c7d8d6518ddd16bc2ee8296..bb319a5f8885aa62c50f2ab1aa862a31722b0852 100644 (file)
@@ -134,6 +134,20 @@ class SessionTest(TestBase, AssertsExecutionResults):
         assert testing.db.connect().execute("select count(1) from users").scalar() == 1
         sess.close()
 
+    def test_flush_noop(self):
+        session = create_session()
+        session.uow = object()
+
+        self.assertRaises(AttributeError, session.flush)
+
+        session = create_session()
+        session.uow = object()
+
+        session.flush(objects=[])
+        session.flush(objects=set())
+        session.flush(objects=())
+        session.flush(objects=iter([]))
+
     @testing.unsupported('sqlite', 'mssql') # TEMP: test causes mssql to hang
     @engines.close_open_connections
     def test_autoflush(self):