"""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):
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):