From 547ac69d9dab78af9a7ccd71ee55102f344065f1 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 16 Mar 2021 17:59:44 -0400 Subject: turn off eager configure_mappers() outside of Query, Load Fixed regression where producing a Core expression construct such as :func:`_sql.select` using ORM entities would eagerly configure the mappers, in an effort to maintain compatibility with the :class:`_orm.Query` object which necessarily does this to support many backref-related legacy cases. However, core :func:`_sql.select` constructs are also used in mapper configurations and such, and to that degree this eager configuration is more of an inconvenience, so eager configure has been disabled for the :func:`_sql.select` and other Core constructs in the absence of ORM loading types of functions such as :class:`_orm.Load`. The change maintains the behavior of :class:`_orm.Query` so that backwards compatibility is maintained. However, when using a :func:`_sql.select` in conjunction with ORM entities, a "backref" that isn't explicitly placed on one of the classes until mapper configure time won't be available unless :func:`_orm.configure_mappers` or the newer :func:`_orm.registry.configure` has been called elsewhere. Prefer using :paramref:`_orm.relationship.back_populates` for more explicit relationship configuration which does not have the eager configure requirement. Fixes: #6066 Change-Id: I7a953ddcc189471fbac63c97c51ab8956f64012e --- lib/sqlalchemy/sql/coercions.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'lib/sqlalchemy/sql') diff --git a/lib/sqlalchemy/sql/coercions.py b/lib/sqlalchemy/sql/coercions.py index 8c7963205..76ba7e214 100644 --- a/lib/sqlalchemy/sql/coercions.py +++ b/lib/sqlalchemy/sql/coercions.py @@ -109,7 +109,14 @@ def _expression_collection_was_a_list(attrname, fnname, args): return args -def expect(role, element, apply_propagate_attrs=None, argname=None, **kw): +def expect( + role, + element, + apply_propagate_attrs=None, + argname=None, + post_inspect=False, + **kw +): if ( role.allows_lambda # note callable() will not invoke a __getattr__() method, whereas @@ -157,7 +164,8 @@ def expect(role, element, apply_propagate_attrs=None, argname=None, **kw): if impl._use_inspection: insp = inspection.inspect(element, raiseerr=False) if insp is not None: - insp._post_inspect + if post_inspect: + insp._post_inspect try: resolved = insp.__clause_element__() except AttributeError: -- cgit v1.2.1