From: Jason Kirtland Date: Tue, 22 Apr 2008 19:29:56 +0000 (+0000) Subject: flush(objects=[]) is a no-op [ticket:928] X-Git-Tag: rel_0_5beta1~178 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f472959846839c259162b36111596ac6a3d78273;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git flush(objects=[]) is a no-op [ticket:928] --- diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py index b7a4aa911e..076727486e 100644 --- a/lib/sqlalchemy/orm/session.py +++ b/lib/sqlalchemy/orm/session.py @@ -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): diff --git a/test/orm/session.py b/test/orm/session.py index e4b42ab1cb..bb319a5f88 100644 --- a/test/orm/session.py +++ b/test/orm/session.py @@ -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):