summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2021-04-20 18:58:34 +0000
committerGerrit Code Review <gerrit@ci3.zzzcomputing.com>2021-04-20 18:58:34 +0000
commit141846612700b5355173e7883f048ffa21ad1f75 (patch)
tree2fed80b78e8553a179249deac8983a04f02dad19 /lib
parent4dfc5762d2d228b01c5ca6cf16f55598e34c054e (diff)
parent4b9e2db51a7e40ff2c4212fe8476fe0c7ba21ca0 (diff)
downloadsqlalchemy-141846612700b5355173e7883f048ffa21ad1f75.tar.gz
Merge "Allow immediateload to use_get for recursive call"
Diffstat (limited to 'lib')
-rw-r--r--lib/sqlalchemy/orm/loading.py4
-rw-r--r--lib/sqlalchemy/orm/strategies.py12
-rw-r--r--lib/sqlalchemy/orm/strategy_options.py3
3 files changed, 14 insertions, 5 deletions
diff --git a/lib/sqlalchemy/orm/loading.py b/lib/sqlalchemy/orm/loading.py
index ea6d0f1fe..cd2ec8301 100644
--- a/lib/sqlalchemy/orm/loading.py
+++ b/lib/sqlalchemy/orm/loading.py
@@ -338,7 +338,9 @@ def get_from_identity(session, mapper, key, passive):
return attributes.PASSIVE_NO_RESULT
elif not passive & attributes.RELATED_OBJECT_OK:
# this mode is used within a flush and the instance's
- # expired state will be checked soon enough, if necessary
+ # expired state will be checked soon enough, if necessary.
+ # also used by immediateloader for a mutually-dependent
+ # o2m->m2m load, :ticket:`6301`
return instance
try:
state._load_expired(state, passive)
diff --git a/lib/sqlalchemy/orm/strategies.py b/lib/sqlalchemy/orm/strategies.py
index 4936049d4..0f68a3fef 100644
--- a/lib/sqlalchemy/orm/strategies.py
+++ b/lib/sqlalchemy/orm/strategies.py
@@ -1237,12 +1237,16 @@ class ImmediateLoader(PostLoader):
populators,
):
def load_immediate(state, dict_, row):
- state.get_impl(self.key).get(
- state, dict_, attributes.PASSIVE_OFF | attributes.NO_RAISE
- )
+ state.get_impl(self.key).get(state, dict_, flags)
if self._check_recursive_postload(context, path):
- return
+ # this will not emit SQL and will only emit for a many-to-one
+ # "use get" load. the "_RELATED" part means it may return
+ # instance even if its expired, since this is a mutually-recursive
+ # load operation.
+ flags = attributes.PASSIVE_NO_FETCH_RELATED | attributes.NO_RAISE
+ else:
+ flags = attributes.PASSIVE_OFF | attributes.NO_RAISE
populators["delayed"].append((self.key, load_immediate))
diff --git a/lib/sqlalchemy/orm/strategy_options.py b/lib/sqlalchemy/orm/strategy_options.py
index 2cab0d0f0..8602f37b6 100644
--- a/lib/sqlalchemy/orm/strategy_options.py
+++ b/lib/sqlalchemy/orm/strategy_options.py
@@ -1380,6 +1380,9 @@ def immediateload(loadopt, attr):
"""Indicate that the given attribute should be loaded using
an immediate load with a per-attribute SELECT statement.
+ The load is achieved using the "lazyloader" strategy and does not
+ fire off any additional eager loaders.
+
The :func:`.immediateload` option is superseded in general
by the :func:`.selectinload` option, which performs the same task
more efficiently by emitting a SELECT for all loaded objects.