]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
Fix subqueryload losing .and_() criteria with of_type()
authorArya Rizky <algojogacor@users.noreply.github.com>
Tue, 12 May 2026 12:45:51 +0000 (19:45 +0700)
committerArya Rizky <algojogacor@users.noreply.github.com>
Tue, 12 May 2026 12:45:51 +0000 (19:45 +0700)
commit879d19a157aae14ef5089a446cd1963cf4a5e7c1
treeaa9f97e6a4df61a2fd3d703000e202b4417b0275
parent1e1c0084b1804eaae8b7f089435241a2b8f4be60
Fix subqueryload losing .and_() criteria with of_type()

Fixed issue where subqueryload would silently ignore additional filter
criteria passed via .and_() when of_type() was also used. Two changes:

1. In _SubqueryLoader._setup_options(), use effective_entity instead of
   self.entity when creating the LoaderCriteriaOption, so that the criteria
   is associated with the correct polymorphic entity (e.g. the of_type()
   target). This matches the behavior of selectinload which already uses
   effective_entity.

2. In _JoinCondition.join_targets mark_exclude_cols(), add a mapper.isa()
   check so that subclass mapper columns are recognized as belonging to
   the relationship target. Previously, only the base class mapper was
   checked via identity comparison (is not self.prop.mapper), causing
   subclass columns to be annotated with should_not_adapt, which prevented
   the ClauseAdapter from rewriting them to use the subquery alias.

The same mapper.isa() fix also resolves #13203 (joinedload variant).

Fixes: #13207
Related: #13203
lib/sqlalchemy/orm/relationships.py
lib/sqlalchemy/orm/strategies.py