From 9e85abb221af13057621ea066af4e15b2f1dfb03 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 26 Mar 2023 12:30:35 -0400 Subject: disable raise sql for the delete cascade Towards maintaining consistency with unit-of-work changes made for :ticket:`5984` and :ticket:`8862`, both of which disable "lazy='raise'" handling within :class:`_orm.Session` processes that aren't triggered by attribute access, the :meth:`_orm.Session.delete` method will now also disable "lazy='raise'" handling when it traverses relationship paths in order to process the "delete" and "delete-orphan" cascade rules. Previously, there was no easy way to generically call :meth:`_orm.Session.delete` on an object that had "lazy='raise'" set up such that only the necessary relationships would be loaded. As "lazy='raise'" is primarily intended to catch SQL loading that emits on attribute access, :meth:`_orm.Session.delete` is now made to behave like other :class:`_orm.Session` methods including :meth:`_orm.Session.merge` as well as :meth:`_orm.Session.flush` along with autoflush. Fixes: #9549 Change-Id: Ie049e66ce2bd35900eae4af0e9b795633303ca63 --- lib/sqlalchemy/orm/relationships.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/sqlalchemy') diff --git a/lib/sqlalchemy/orm/relationships.py b/lib/sqlalchemy/orm/relationships.py index 05fa17a96..8d9f3c644 100644 --- a/lib/sqlalchemy/orm/relationships.py +++ b/lib/sqlalchemy/orm/relationships.py @@ -1495,7 +1495,7 @@ class RelationshipProperty( if type_ != "delete" or self.passive_deletes: passive = PassiveFlag.PASSIVE_NO_INITIALIZE else: - passive = PassiveFlag.PASSIVE_OFF + passive = PassiveFlag.PASSIVE_OFF | PassiveFlag.NO_RAISE if type_ == "save-update": tuples = state.manager[self.key].impl.get_all_pending(state, dict_) -- cgit v1.2.1