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
if (
parentmapper_for_element is not self.prop.parent
and parentmapper_for_element is not self.prop.mapper
+ and not (
+ parentmapper_for_element is not None
+ and parentmapper_for_element.isa(
+ self.prop.mapper
+ )
+ )
and elem not in self._secondary_lineage_set
):
return _safe_annotate(elem, annotations)
if loadopt and loadopt._extra_criteria:
new_options += (
orm_util.LoaderCriteriaOption(
- self.entity,
+ effective_entity,
loadopt._generate_extra_criteria(context),
),
)