]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
create new approach for deeply nested post loader options
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 16 Jun 2022 17:35:16 +0000 (13:35 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 18 Jun 2022 21:06:53 +0000 (17:06 -0400)
commit64b9d9886f0bf4bbb5f0d019ecdbe579cd495141
treeefca9e29f538c845d3268c0dedbd8f9c73d2a9bd
parentc3102b85c40ab4578a0f56ee1e8eee4a6e0aed55
create new approach for deeply nested post loader options

Added very experimental feature to the :func:`_orm.selectinload` and
:func:`_orm.immediateload` loader options called
:paramref:`_orm.selectinload.recursion_depth` /
:paramref:`_orm.immediateload.recursion_depth` , which allows a single
loader option to automatically recurse into self-referential relationships.
Is set to an integer indicating depth, and may also be set to -1 to
indicate to continue loading until no more levels deep are found.
Major internal changes to :func:`_orm.selectinload` and
:func:`_orm.immediateload` allow this feature to work while continuing
to make correct use of the compilation cache, as well as not using
arbitrary recursion, so any level of depth is supported (though would
emit that many queries).  This may be useful for
self-referential structures that must be loaded fully eagerly, such as when
using asyncio.

A warning is also emitted when loader options are connected together with
arbitrary lengths (that is, without using the new ``recursion_depth``
option) when excessive recursion depth is detected in related object
loading. This operation continues to use huge amounts of memory and
performs extremely poorly; the cache is disabled when this condition is
detected to protect the cache from being flooded with arbitrary statements.

Fixes: #8126
Change-Id: I9f162e0a09c1ed327dd19498aac193f649333a01
doc/build/changelog/unreleased_20/8126.rst [new file with mode: 0644]
lib/sqlalchemy/orm/context.py
lib/sqlalchemy/orm/loading.py
lib/sqlalchemy/orm/path_registry.py
lib/sqlalchemy/orm/strategies.py
lib/sqlalchemy/orm/strategy_options.py
lib/sqlalchemy/testing/assertions.py
test/orm/test_recursive_loaders.py [new file with mode: 0644]
test/orm/test_selectin_relations.py
test/profiles.txt