--- /dev/null
+.. change::
+ :tags: bug, orm
+ :tickets: 10365
+
+ Fixed bug where ORM :func:`_orm.with_loader_criteria` would not apply
+ itself to a :meth:`_sql.Select.join` where the ON clause were given as a
+ plain SQL comparison, rather than as a relationship target or similar.
+
+ This is a backport of the same issue fixed in version 2.0 for 2.0.22.
else:
prop = None
+ left_selectable = left_info.selectable
if prop:
- left_selectable = left_info.selectable
-
if sql_util.clause_is_present(on_selectable, left_selectable):
adapt_from = on_selectable
else:
self._target_adapter = target_adapter
- # we don't use the normal coercions logic for _ORMJoin
- # (probably should), so do some gymnastics to get the entity.
- # logic here is for #8721, which was a major bug in 1.4
- # for almost two years, not reported/fixed until 1.4.43 (!)
- if left_info.is_selectable:
- parententity = left_selectable._annotations.get(
- "parententity", None
- )
- elif left_info.is_mapper or left_info.is_aliased_class:
- parententity = left_info
- else:
- parententity = None
+ # we don't use the normal coercions logic for _ORMJoin
+ # (probably should), so do some gymnastics to get the entity.
+ # logic here is for #8721, which was a major bug in 1.4
+ # for almost two years, not reported/fixed until 1.4.43 (!)
+ if left_info.is_selectable:
+ parententity = left_selectable._annotations.get(
+ "parententity", None
+ )
+ elif left_info.is_mapper or left_info.is_aliased_class:
+ parententity = left_info
+ else:
+ parententity = None
- if parententity is not None:
- self._annotations = self._annotations.union(
- {"parententity": parententity}
- )
+ if parententity is not None:
+ self._annotations = self._annotations.union(
+ {"parententity": parententity}
+ )
- augment_onclause = onclause is None and _extra_criteria
+ augment_onclause = bool(_extra_criteria) and not prop
expression.Join.__init__(self, left, right, onclause, isouter, full)
if augment_onclause:
N801,N802,N806,
RST304,RST303,RST299,RST399,
W503,W504
+ U100
+ IS001
exclude = .venv,.git,.tox,dist,doc,*egg,build
import-order-style = google
application-import-names = sqlalchemy,test
.join(User.addresses)
.options(with_loader_criteria(User, User.name != "name")),
),
+ (
+ # issue #10365
+ lambda User, Address: select(Address)
+ .select_from(User)
+ .join(Address, User.id == Address.user_id)
+ .options(with_loader_criteria(User, User.name != "name")),
+ ),
(
lambda User, Address: select(Address)
.select_from(orm_join(User, Address, User.addresses))
.join(User.addresses)
.options(with_loader_criteria(User, User.name != "name")),
),
+ (
+ # issue #10365 - this seems to have already worked
+ lambda User, Address: select(Address.id, User.id)
+ .select_from(User)
+ .join(Address, User.id == Address.user_id)
+ .options(with_loader_criteria(User, User.name != "name")),
+ ),
(
lambda User, Address: select(Address.id, User.id)
.select_from(orm_join(User, Address, User.addresses))
with_loader_criteria(Address, Address.email_address != "email")
),
),
+ (
+ # issue #10365
+ lambda User, Address: select(Address)
+ .select_from(User)
+ .join(Address, User.id == Address.user_id)
+ .options(
+ with_loader_criteria(Address, Address.email_address != "email")
+ ),
+ ),
(
# for orm_join(), this is set up before we have the context
# available that allows with_loader_criteria to be set up