--- /dev/null
+.. change::
+ :tags: bug, regression, orm
+ :tickets: 6680
+
+ Fixed regression in ORM regarding an internal reconstitution step for the
+ func:`_orm.with_polymorphic` construct, when the user-facing object is
+ garbage collected as the query is processed. The reconstitution was not
+ ensuring the sub-entities for the "polymorphic" case were handled, leading
+ to an ``AttributeError``.
obj = cls.__new__(cls)
obj.__name__ = "AliasedClass_%s" % aliased_insp.mapper.class_.__name__
obj._aliased_insp = aliased_insp
+
+ if aliased_insp._is_with_polymorphic:
+ for sub_aliased_insp in aliased_insp._with_polymorphic_entities:
+ if sub_aliased_insp is not aliased_insp:
+ ent = AliasedClass._reconstitute_from_aliased_insp(
+ sub_aliased_insp
+ )
+ setattr(obj, sub_aliased_insp.class_.__name__, ent)
+
return obj
def __getattr__(self, key):
from sqlalchemy import and_
from sqlalchemy import exc
from sqlalchemy import or_
+from sqlalchemy import select
from sqlalchemy import testing
from sqlalchemy.orm import with_polymorphic
from sqlalchemy.testing import eq_
self.assert_sql_count(testing.db, go, 1)
- def test_col_expression_base_plus_two_subs(self):
+ @testing.combinations((True,), (False,), argnames="use_star")
+ def test_col_expression_base_plus_two_subs(self, use_star):
sess = fixture_session()
- pa = with_polymorphic(Person, [Engineer, Manager])
+
+ if use_star:
+ pa = with_polymorphic(Person, "*")
+ else:
+ pa = with_polymorphic(Person, [Engineer, Manager])
eq_(
sess.query(
[("dilbert", "java", None), ("dogbert", None, "dogbert")],
)
+ def test_orm_entity_w_gc(self):
+ """test #6680"""
+ sess = fixture_session()
+
+ stmt = select(with_polymorphic(Person, "*"))
+
+ eq_(len(sess.execute(stmt).all()), 5)
+
def test_join_to_join_entities(self):
sess = fixture_session()
pa = with_polymorphic(Person, [Engineer])