summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/attributes.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2018-11-01 11:11:03 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2018-11-02 09:23:24 -0400
commitbc04e63475e94f99a6e21a48824adf6ec6b37319 (patch)
tree3d4f49781e874deb440b65c2dc250b9cac000480 /lib/sqlalchemy/orm/attributes.py
parentbc7c212370621a26629392cf247492c773fa63fd (diff)
downloadsqlalchemy-bc04e63475e94f99a6e21a48824adf6ec6b37319.tar.gz
Add new NO_RAISE attribute flag and specify for m2o history load
Added new behavior to the lazy load that takes place when the "old" value of a many-to-one is retrieved, such that exceptions which would be raised due to either ``lazy="raise"`` or a detached session error are skipped. Fixes: #4353 Change-Id: I6c6c77613e93061a909f5062b70b17e8913fc9ee
Diffstat (limited to 'lib/sqlalchemy/orm/attributes.py')
-rw-r--r--lib/sqlalchemy/orm/attributes.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py
index 3eaa41e8f..ff730d745 100644
--- a/lib/sqlalchemy/orm/attributes.py
+++ b/lib/sqlalchemy/orm/attributes.py
@@ -24,7 +24,8 @@ from .base import PASSIVE_NO_RESULT, ATTR_WAS_SET, ATTR_EMPTY, NO_VALUE,\
NEVER_SET, NO_CHANGE, CALLABLES_OK, SQL_OK, RELATED_OBJECT_OK,\
INIT_OK, NON_PERSISTENT_OK, LOAD_AGAINST_COMMITTED, PASSIVE_OFF,\
PASSIVE_RETURN_NEVER_SET, PASSIVE_NO_INITIALIZE, PASSIVE_NO_FETCH,\
- PASSIVE_NO_FETCH_RELATED, PASSIVE_ONLY_PERSISTENT, NO_AUTOFLUSH
+ PASSIVE_NO_FETCH_RELATED, PASSIVE_ONLY_PERSISTENT, NO_AUTOFLUSH, \
+ NO_RAISE
from .base import state_str, instance_str
@@ -753,7 +754,7 @@ class ScalarObjectAttributeImpl(ScalarAttributeImpl):
else:
old = self.get(
state, dict_, passive=PASSIVE_NO_FETCH ^ INIT_OK |
- LOAD_AGAINST_COMMITTED)
+ LOAD_AGAINST_COMMITTED | NO_RAISE)
self.fire_remove_event(state, dict_, old, self._remove_token)
@@ -817,7 +818,7 @@ class ScalarObjectAttributeImpl(ScalarAttributeImpl):
else:
old = self.get(
state, dict_, passive=PASSIVE_NO_FETCH ^ INIT_OK |
- LOAD_AGAINST_COMMITTED)
+ LOAD_AGAINST_COMMITTED | NO_RAISE)
if check_old is not None and \
old is not PASSIVE_NO_RESULT and \
@@ -1253,7 +1254,9 @@ def backref_listeners(attribute, key, uselist):
return child
def emit_backref_from_collection_remove_event(state, child, initiator):
- if child is not None:
+ if child is not None and \
+ child is not PASSIVE_NO_RESULT and \
+ child is not NEVER_SET:
child_state, child_dict = instance_state(child),\
instance_dict(child)
child_impl = child_state.manager[key].impl