diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-03-23 10:23:23 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-03-23 10:23:23 -0400 |
| commit | 8bf920d52ddd4ec5f62a00fb9db370a076aa375d (patch) | |
| tree | 3832f220051ba0c73efffc47f5827a50b4629e18 /lib/sqlalchemy | |
| parent | 070103630bb158e47230b8c6aadc57c3378bf425 (diff) | |
| download | sqlalchemy-8bf920d52ddd4ec5f62a00fb9db370a076aa375d.tar.gz | |
warn / document for Query.with_polymorphic() with with_loader_criteria()
These are illustrated as not working in #6111. As this is
a highly complex and legacy method, encourage users to
migrate off of it before using with_loader_criteria().
Fixes: #6111
Change-Id: I63c8187020c631d83259ea2200b66eabf74a0d0d
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/orm/query.py | 13 | ||||
| -rw-r--r-- | lib/sqlalchemy/orm/util.py | 7 |
2 files changed, 18 insertions, 2 deletions
diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index 96b4c5624..7e2fde749 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -786,6 +786,14 @@ class Query( ): """Load columns for inheriting classes. + This is a legacy method which is replaced by the + :func:`_orm.with_polymorphic` function. + + .. warning:: The :meth:`_orm.Query.with_polymorphic` method does + **not** support 1.4/2.0 style features including + :func:`_orm.with_loader_criteria`. Please migrate code + to use :func:`_orm.with_polymorphic`. + :meth:`_query.Query.with_polymorphic` applies transformations to the "main" mapped class represented by this :class:`_query.Query`. The "main" mapped class here means the :class:`_query.Query` @@ -796,8 +804,9 @@ class Query( purposes of load-time efficiency as well as the ability to use these columns at query time. - See the documentation section :ref:`with_polymorphic` for - details on how this method is used. + .. seealso:: + + :ref:`with_polymorphic` - illustrates current patterns """ diff --git a/lib/sqlalchemy/orm/util.py b/lib/sqlalchemy/orm/util.py index 37be077be..941c5eb08 100644 --- a/lib/sqlalchemy/orm/util.py +++ b/lib/sqlalchemy/orm/util.py @@ -1070,6 +1070,13 @@ class LoaderCriteriaOption(CriteriaOption): # if options to limit the criteria to immediate query only, # use compile_state.attributes instead + if compile_state.compile_options._with_polymorphic_adapt_map: + util.warn( + "The with_loader_criteria() function may not work " + "correctly with the legacy Query.with_polymorphic() feature. " + "Please migrate code to use the with_polymorphic() standalone " + "function before using with_loader_criteria()." + ) if not compile_state.compile_options._for_refresh_state: self.get_global_criteria(compile_state.global_attributes) |
