attributes, which has the effect of the attribute being undeferred
for the next refesh, causing an unexpected load of the attribute.
+ .. change::
+ :tags: bug, orm
+ :tickets: 4040
+
+ Fixed bug involving delete-orphan cascade where a related item
+ that becomes an orphan before the parent object is part of a
+ session is still tracked as moving into orphan status, which results
+ in it being expunged from the session rather than being flushed.
+
+ .. note:: This fix was inadvertently merged during the 1.2.0b3
+ release and was **not added to the changelog** at that time.
+ This changelog note was added to the release retroactively as of
+ version 1.2.13.
+
.. change::
:tags: bug, orm
:tickets: 4026
is_persistent_orphan = is_orphan and state.has_identity
- if is_orphan and not is_persistent_orphan and state._orphaned_outside_of_session:
+ if is_orphan and not is_persistent_orphan and \
+ state._orphaned_outside_of_session:
self._expunge_states([state])
else:
_reg = flush_context.register_object(
if sess and item_state in sess._new:
sess.expunge(item)
else:
+ # the related item may or may not itself be in a
+ # Session, however the parent for which we are catching
+ # the event is not in a session, so memoize this on the
+ # item
item_state._orphaned_outside_of_session = True
def set_(state, newvalue, oldvalue, initiator):
u.orders.remove(o1)
assert o1 not in sess
+ def test_remove_pending_from_pending_parent(self):
+ # test issue #4040
+
+ User, Order = self.classes.User, self.classes.Order
+
+ sess = Session()
+
+ u = User(name='jack')
+
+ o1 = Order()
+ sess.add(o1)
+
+ # object becomes an orphan, but parent is not in session
+ u.orders.append(o1)
+ u.orders.remove(o1)
+
+ sess.add(u)
+
+ assert o1 in sess
+
+ sess.flush()
+
+ assert o1 not in sess
+
def test_delete(self):
User, users, orders, Order = (self.classes.User,
self.tables.users,