summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/orm/attributes.py11
-rw-r--r--lib/sqlalchemy/orm/base.py6
-rw-r--r--lib/sqlalchemy/orm/strategies.py5
3 files changed, 17 insertions, 5 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
diff --git a/lib/sqlalchemy/orm/base.py b/lib/sqlalchemy/orm/base.py
index e06e1fc78..62b4f59a9 100644
--- a/lib/sqlalchemy/orm/base.py
+++ b/lib/sqlalchemy/orm/base.py
@@ -104,6 +104,12 @@ NO_AUTOFLUSH = util.symbol(
canonical=64
)
+NO_RAISE = util.symbol(
+ "NO_RAISE",
+ """Loader callables should not raise any assertions""",
+ canonical=128
+)
+
# pre-packaged sets of flags used as inputs
PASSIVE_OFF = util.symbol(
"PASSIVE_OFF",
diff --git a/lib/sqlalchemy/orm/strategies.py b/lib/sqlalchemy/orm/strategies.py
index b9abf0647..9d83952d3 100644
--- a/lib/sqlalchemy/orm/strategies.py
+++ b/lib/sqlalchemy/orm/strategies.py
@@ -585,11 +585,14 @@ class LazyLoader(AbstractRelationshipLoader, util.MemoizedSlots):
):
return attributes.PASSIVE_NO_RESULT
- if self._raise_always:
+ if self._raise_always and not passive & attributes.NO_RAISE:
self._invoke_raise_load(state, passive, "raise")
session = _state_session(state)
if not session:
+ if passive & attributes.NO_RAISE:
+ return attributes.PASSIVE_NO_RESULT
+
raise orm_exc.DetachedInstanceError(
"Parent instance %s is not bound to a Session; "
"lazy load operation of attribute '%s' cannot proceed" %