]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
Raise for unexpected polymorphic identity
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 28 Jan 2020 21:44:53 +0000 (16:44 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 30 Jan 2020 03:02:34 +0000 (22:02 -0500)
commitc741b89bd57eb31b7a1bbd187a4d159bdfea5111
tree011bce072c9093cc4b648c669212a58bbd9a3d57
parent0cc2695510c0f0b09328e4cdf8d3ae29ac7f7abd
Raise for unexpected polymorphic identity

A query that is against an mapped inheritance subclass which also uses
:meth:`.Query.select_entity_from` or a similar technique in order  to
provide an existing subquery to SELECT from, will now raise an error if the
given subquery returns entities that do not correspond to the given
subclass, that is, they are sibling or superclasses in the same hierarchy.
Previously, these would be returned without error.  Additionally, if the
inheritance mapping is a single-inheritance mapping, the given subquery
must apply the appropriate filtering against the polymorphic discriminator
column in order to avoid this error; previously, the :class:`.Query` would
add this criteria to the outside query however this interferes with some
kinds of query that return other kinds of entities as well.

Fixes: #5122
Change-Id: I60cf8c1300d5bb279ad99f0f01fefe7e008a159b
doc/build/changelog/migration_14.rst
doc/build/changelog/unreleased_14/5122.rst [new file with mode: 0644]
lib/sqlalchemy/orm/loading.py
lib/sqlalchemy/orm/query.py
test/orm/inheritance/test_basic.py
test/orm/inheritance/test_single.py