summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-03-16 17:59:44 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2021-03-16 17:59:44 -0400
commit547ac69d9dab78af9a7ccd71ee55102f344065f1 (patch)
tree6283e06cba3d88142a13b12cd72d0bb32e30e0e1 /lib/sqlalchemy/sql
parent4a827330616a90b1fa0a10f86d8e7cb6e92047ba (diff)
downloadsqlalchemy-547ac69d9dab78af9a7ccd71ee55102f344065f1.tar.gz
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
Diffstat (limited to 'lib/sqlalchemy/sql')
-rw-r--r--lib/sqlalchemy/sql/coercions.py12
1 files changed, 10 insertions, 2 deletions
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: