summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2022-06-16 14:46:11 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2022-06-16 14:46:11 -0400
commitc3102b85c40ab4578a0f56ee1e8eee4a6e0aed55 (patch)
tree3a0589663745b1a0a63b7b098053a77184e9d5c6 /lib/sqlalchemy/orm
parentefd4e6dd8a73b956c860d796606f8e6ad652c292 (diff)
downloadsqlalchemy-c3102b85c40ab4578a0f56ee1e8eee4a6e0aed55.tar.gz
Revert "add auto_recurse option to selectinload, immediateload"
this option works very badly with caching and the API is likely not what we want either. Work continues for #8126 including that the additional work in I9f162e0a09c1ed327dd19498aac193f649333a01 tries to add new recursive features. This reverts commit b3a1162553879d1369154e920f3f4129020bb88e.
Diffstat (limited to 'lib/sqlalchemy/orm')
-rw-r--r--lib/sqlalchemy/orm/strategies.py32
-rw-r--r--lib/sqlalchemy/orm/strategy_options.py71
2 files changed, 10 insertions, 93 deletions
diff --git a/lib/sqlalchemy/orm/strategies.py b/lib/sqlalchemy/orm/strategies.py
index d4297f84c..c4c0fb180 100644
--- a/lib/sqlalchemy/orm/strategies.py
+++ b/lib/sqlalchemy/orm/strategies.py
@@ -43,7 +43,6 @@ from .interfaces import LoaderStrategy
from .interfaces import StrategizedProperty
from .session import _state_session
from .state import InstanceState
-from .strategy_options import Load
from .util import _none_set
from .util import AliasedClass
from .. import event
@@ -1260,24 +1259,8 @@ class ImmediateLoader(PostLoader):
populators,
):
def load_immediate(state, dict_, row):
- if auto_recurse:
- new_opt = Load(loadopt.path.entity)
- new_opt.context = (loadopt._recurse(),)
- state.load_options += (new_opt,)
-
state.get_impl(self.key).get(state, dict_, flags)
- if loadopt and loadopt.local_opts.get("auto_recurse", False):
- if not self.parent_property._is_self_referential:
- raise sa_exc.InvalidRequestError(
- f"auto_recurse option on relationship "
- f"{self.parent_property} not valid for "
- "non-self-referential relationship"
- )
- auto_recurse = True
- else:
- auto_recurse = False
-
if self._check_recursive_postload(context, path):
# this will not emit SQL and will only emit for a many-to-one
# "use get" load. the "_RELATED" part means it may return
@@ -3020,21 +3003,6 @@ class SelectInLoader(PostLoader, util.MemoizedSlots):
),
)
- if loadopt and loadopt.local_opts.get("auto_recurse", False):
- if not self.parent_property._is_self_referential:
- # how could we do more recursion? auto_recurse is put on
- # the last option in a chain, then _recurse() will walk
- # backwards up the path to see where the pattern repeats
- # and splice it based on that
- raise sa_exc.InvalidRequestError(
- f"auto_recurse option on relationship "
- f"{self.parent_property} not valid for "
- "non-self-referential relationship"
- )
- new_opt = Load(effective_entity)
- new_opt.context = (loadopt._recurse(),)
- new_options += (new_opt,)
-
q = q.options(*new_options)._update_compile_options(
{"_current_path": effective_path}
)
diff --git a/lib/sqlalchemy/orm/strategy_options.py b/lib/sqlalchemy/orm/strategy_options.py
index 05089291f..593e2abd2 100644
--- a/lib/sqlalchemy/orm/strategy_options.py
+++ b/lib/sqlalchemy/orm/strategy_options.py
@@ -343,7 +343,7 @@ class _AbstractLoad(traversals.GenerativeOnTraversal, LoaderOption):
return self._set_relationship_strategy(attr, {"lazy": "subquery"})
def selectinload(
- self: Self_AbstractLoad, attr: _AttrType, auto_recurse: bool = False
+ self: Self_AbstractLoad, attr: _AttrType
) -> Self_AbstractLoad:
"""Indicate that the given attribute should be loaded using
SELECT IN eager loading.
@@ -365,21 +365,7 @@ class _AbstractLoad(traversals.GenerativeOnTraversal, LoaderOption):
query(Order).options(
lazyload(Order.items).selectinload(Item.keywords))
- :param auto_recurse: boolean; may be set to True when setting the
- option on a self-referential relationship, which indicates that
- "selectin" loading will continue an arbitrary number of levels deep
- until no more items are found.
-
- .. note:: The :paramref:`_orm.selectinload.auto_recurse` option
- currently supports only self-referential relationships. There
- is not yet an option to automatically traverse recursive structures
- with more than one relationship involved.
-
- .. warning:: This parameter is new and experimental and should be
- treated as "alpha" status
-
- .. versionadded:: 2.0 added :paramref:`_orm.selectinload.auto_recurse`
-
+ .. versionadded:: 1.2
.. seealso::
@@ -388,9 +374,7 @@ class _AbstractLoad(traversals.GenerativeOnTraversal, LoaderOption):
:ref:`selectin_eager_loading`
"""
- return self._set_relationship_strategy(
- attr, {"lazy": "selectin"}, opts={"auto_recurse": auto_recurse}
- )
+ return self._set_relationship_strategy(attr, {"lazy": "selectin"})
def lazyload(
self: Self_AbstractLoad, attr: _AttrType
@@ -411,7 +395,7 @@ class _AbstractLoad(traversals.GenerativeOnTraversal, LoaderOption):
return self._set_relationship_strategy(attr, {"lazy": "select"})
def immediateload(
- self: Self_AbstractLoad, attr: _AttrType, auto_recurse: bool = False
+ self: Self_AbstractLoad, attr: _AttrType
) -> Self_AbstractLoad:
"""Indicate that the given attribute should be loaded using
an immediate load with a per-attribute SELECT statement.
@@ -426,23 +410,6 @@ class _AbstractLoad(traversals.GenerativeOnTraversal, LoaderOption):
This function is part of the :class:`_orm.Load` interface and supports
both method-chained and standalone operation.
- :param auto_recurse: boolean; may be set to True when setting the
- option on a self-referential relationship, which indicates that
- "immediate" loading will continue an arbitrary number of levels deep
- until no more items are found.
-
- .. note:: The :paramref:`_orm.immediateload.auto_recurse` option
- currently supports only self-referential relationships. There
- is not yet an option to automatically traverse recursive structures
- with more than one relationship involved.
-
- .. warning:: This parameter is new and experimental and should be
- treated as "alpha" status
-
- .. versionadded:: 2.0 added
- :paramref:`_orm.immediateload.auto_recurse`
-
-
.. seealso::
:ref:`loading_toplevel`
@@ -450,9 +417,7 @@ class _AbstractLoad(traversals.GenerativeOnTraversal, LoaderOption):
:ref:`selectin_eager_loading`
"""
- loader = self._set_relationship_strategy(
- attr, {"lazy": "immediate"}, opts={"auto_recurse": auto_recurse}
- )
+ loader = self._set_relationship_strategy(attr, {"lazy": "immediate"})
return loader
def noload(self: Self_AbstractLoad, attr: _AttrType) -> Self_AbstractLoad:
@@ -1725,15 +1690,7 @@ class _LoadElement(
def __init__(self) -> None:
raise NotImplementedError()
- def _recurse(self) -> _LoadElement:
- cloned = self._clone()
- cloned.path = PathRegistry.coerce(self.path[:] + self.path[-2:])
-
- return cloned
-
- def _prepend_path_from(
- self, parent: Union[Load, _LoadElement]
- ) -> _LoadElement:
+ def _prepend_path_from(self, parent):
"""adjust the path of this :class:`._LoadElement` to be
a subpath of that of the given parent :class:`_orm.Load` object's
path.
@@ -2380,12 +2337,8 @@ def subqueryload(*keys: _AttrType) -> _AbstractLoad:
@loader_unbound_fn
-def selectinload(
- *keys: _AttrType, auto_recurse: bool = False
-) -> _AbstractLoad:
- return _generate_from_keys(
- Load.selectinload, keys, False, {"auto_recurse": auto_recurse}
- )
+def selectinload(*keys: _AttrType) -> _AbstractLoad:
+ return _generate_from_keys(Load.selectinload, keys, False, {})
@loader_unbound_fn
@@ -2394,12 +2347,8 @@ def lazyload(*keys: _AttrType) -> _AbstractLoad:
@loader_unbound_fn
-def immediateload(
- *keys: _AttrType, auto_recurse: bool = False
-) -> _AbstractLoad:
- return _generate_from_keys(
- Load.immediateload, keys, False, {"auto_recurse": auto_recurse}
- )
+def immediateload(*keys: _AttrType) -> _AbstractLoad:
+ return _generate_from_keys(Load.immediateload, keys, False, {})
@loader_unbound_fn