From: Mike Bayer Date: Tue, 4 Jan 2011 15:55:46 +0000 (-0500) Subject: - Fixed bug whereby "passive_deletes='all'" wasn't passing X-Git-Tag: rel_0_7b1~91 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=848a56ea57154c65943d1efd278c78e36500fb28;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Fixed bug whereby "passive_deletes='all'" wasn't passing the correct symbols to lazy loaders during flush, thereby causing an unwarranted load. [ticket:2013] --- diff --git a/CHANGES b/CHANGES index 6491cf7419..65b403d4d1 100644 --- a/CHANGES +++ b/CHANGES @@ -29,6 +29,10 @@ CHANGES that weren't previously saved in the "mutable changes" dictionary. + - Fixed bug whereby "passive_deletes='all'" wasn't passing + the correct symbols to lazy loaders during flush, thereby + causing an unwarranted load. [ticket:2013] + - Fixed bug which prevented composite mapped attributes from being used on a mapped select statement. [ticket:1997]. Note the workings of composite are slated to diff --git a/lib/sqlalchemy/orm/dependency.py b/lib/sqlalchemy/orm/dependency.py index 8acf77ad8d..e3e2f5d567 100644 --- a/lib/sqlalchemy/orm/dependency.py +++ b/lib/sqlalchemy/orm/dependency.py @@ -26,6 +26,9 @@ class DependencyProcessor(object): self.passive_deletes = prop.passive_deletes self.passive_updates = prop.passive_updates self.enable_typechecks = prop.enable_typechecks + self._passive_delete_flag = self.passive_deletes and \ + attributes.PASSIVE_NO_INITIALIZE or \ + attributes.PASSIVE_OFF self.key = prop.key if not self.prop.synchronize_pairs: raise sa_exc.ArgumentError( @@ -390,7 +393,7 @@ class OneToManyDP(DependencyProcessor): history = uowcommit.get_attribute_history( state, self.key, - passive=self.passive_deletes) + passive=self._passive_delete_flag) if history: for child in history.deleted: if child is not None and self.hasparent(child) is False: @@ -466,7 +469,7 @@ class OneToManyDP(DependencyProcessor): history = uowcommit.get_attribute_history( state, self.key, - passive=self.passive_deletes) + passive=self._passive_delete_flag) if history: for child in history.deleted: if child is not None and \ @@ -646,7 +649,7 @@ class ManyToOneDP(DependencyProcessor): history = uowcommit.get_attribute_history( state, self.key, - passive=self.passive_deletes) + passive=self._passive_delete_flag) if history: if self.cascade.delete_orphan: todelete = history.sum() @@ -669,7 +672,7 @@ class ManyToOneDP(DependencyProcessor): history = uowcommit.get_attribute_history( state, self.key, - passive=self.passive_deletes) + passive=self._passive_delete_flag) if history: ret = True for child in history.deleted: @@ -697,7 +700,7 @@ class ManyToOneDP(DependencyProcessor): history = uowcommit.get_attribute_history( state, self.key, - passive=self.passive_deletes) + passive=self._passive_delete_flag) if history: self._post_update(state, uowcommit, history.sum()) @@ -906,7 +909,7 @@ class ManyToManyDP(DependencyProcessor): history = uowcommit.get_attribute_history( state, self.key, - passive=self.passive_deletes) + passive=self._passive_delete_flag) def presort_saves(self, uowcommit, states): if not self.passive_updates: @@ -954,7 +957,7 @@ class ManyToManyDP(DependencyProcessor): history = uowcommit.get_attribute_history( state, self.key, - passive=self.passive_deletes) + passive=self._passive_delete_flag) if history: for child in history.non_added(): if child is None or \ diff --git a/lib/sqlalchemy/orm/unitofwork.py b/lib/sqlalchemy/orm/unitofwork.py index f1c5fcfc68..07c9c2b6d6 100644 --- a/lib/sqlalchemy/orm/unitofwork.py +++ b/lib/sqlalchemy/orm/unitofwork.py @@ -149,7 +149,7 @@ class UOWTransaction(object): self.states[state] = (isdelete, True) - def get_attribute_history(self, state, key, passive=True): + def get_attribute_history(self, state, key, passive=attributes.PASSIVE_NO_INITIALIZE): """facade to attributes.get_state_history(), including caching of results.""" hashkey = ("history", state, key) diff --git a/test/orm/test_unitofwork.py b/test/orm/test_unitofwork.py index d5cd469162..0625b59c97 100644 --- a/test/orm/test_unitofwork.py +++ b/test/orm/test_unitofwork.py @@ -561,16 +561,14 @@ class ExtraPassiveDeletesTest(_base.MappedTest): @testing.resolve_artifact_names def test_assertions(self): mapper(MyOtherClass, myothertable) - try: - mapper(MyClass, mytable, properties={ - 'children':relationship(MyOtherClass, + assert_raises_message( + sa.exc.ArgumentError, + "Can't set passive_deletes='all' in conjunction with 'delete' " + "or 'delete-orphan' cascade", + relationship, MyOtherClass, passive_deletes='all', - cascade="all")}) - assert False - except sa.exc.ArgumentError, e: - eq_(str(e), - "Can't set passive_deletes='all' in conjunction with 'delete' " - "or 'delete-orphan' cascade") + cascade="all" + ) @testing.resolve_artifact_names def test_extra_passive(self): @@ -617,6 +615,23 @@ class ExtraPassiveDeletesTest(_base.MappedTest): mc.children[0].data = 'some new data' assert_raises(sa.exc.DBAPIError, session.flush) + @testing.resolve_artifact_names + def test_dont_emit(self): + mapper(MyOtherClass, myothertable) + mapper(MyClass, mytable, properties={ + 'children': relationship(MyOtherClass, + passive_deletes='all', + cascade="save-update")}) + session = Session() + mc = MyClass() + session.add(mc) + session.commit() + mc.id + + session.delete(mc) + + # no load for "children" should occur + self.assert_sql_count(testing.db, session.flush, 1) class ColumnCollisionTest(_base.MappedTest): """Ensure the mapper doesn't break bind param naming rules on flush."""