From b84c3b34694f36255e203af5a9d531ff89464bdc Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 1 Mar 2009 23:53:58 +0000 Subject: [PATCH] - The "objects" argument to session.flush() is deprecated. State which represents the linkage between a parent and child object does not support "flushed" status on one side of the link and not the other, so supporting this operation leads to misleading results. [ticket:1315] --- CHANGES | 7 +++++++ lib/sqlalchemy/orm/session.py | 7 +++++++ test/orm/cascade.py | 3 ++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index f47e3ebcb8..d2d9304e73 100644 --- a/CHANGES +++ b/CHANGES @@ -6,6 +6,13 @@ CHANGES 0.5.3 ===== - orm + - The "objects" argument to session.flush() is deprecated. + State which represents the linkage between a parent and + child object does not support "flushed" status on + one side of the link and not the other, so supporting + this operation leads to misleading results. + [ticket:1315] + - Query now implements __clause_element__() which produces its selectable, which means a Query instance can be accepted in many SQL expressions, including col.in_(query), diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py index 1c061c7ebf..5e01443a68 100644 --- a/lib/sqlalchemy/orm/session.py +++ b/lib/sqlalchemy/orm/session.py @@ -1333,8 +1333,15 @@ class Session(object): objects Optional; a list or tuple collection. Restricts the flush operation to only these objects, rather than all pending changes. + Deprecated - this flag prevents the session from properly maintaining + accounting among inter-object relations and can cause invalid results. """ + + if objects: + util.warn_deprecated( + "The 'objects' argument to session.flush() is deprecated; " + "Please do not add objects to the session which should not yet be persisted.") if self._flushing: raise sa_exc.InvalidRequestError("Session is already flushing") diff --git a/test/orm/cascade.py b/test/orm/cascade.py index 746dc0e52f..c827a85ced 100644 --- a/test/orm/cascade.py +++ b/test/orm/cascade.py @@ -1200,7 +1200,7 @@ class PartialFlushTest(_base.MappedTest): Column("parent_id", Integer, ForeignKey("parent.id")) ) - + @testing.uses_deprecated() @testing.resolve_artifact_names def test_o2m_m2o(self): class Base(_base.ComparableEntity): @@ -1250,6 +1250,7 @@ class PartialFlushTest(_base.MappedTest): assert c2 in sess and c2 not in sess.new assert b1 in sess and b1 in sess.new + @testing.uses_deprecated() @testing.resolve_artifact_names def test_circular_sort(self): """test ticket 1306""" -- 2.47.3