diff options
| author | mike bayer <mike_mp@zzzcomputing.com> | 2022-10-11 22:18:48 +0000 |
|---|---|---|
| committer | Gerrit Code Review <gerrit@ci3.zzzcomputing.com> | 2022-10-11 22:18:48 +0000 |
| commit | fd485536664967d5ffad34b3184e7b63d0816d39 (patch) | |
| tree | 6e4d693f05b6e592cde83c43a6a83c1eb6ffd3cf /lib/sqlalchemy/orm | |
| parent | c4b06123ff6f64d06aa401a97f51a9a391941094 (diff) | |
| parent | c35921b79e1683d3738a69f8ff6a892c3c2846e2 (diff) | |
| download | sqlalchemy-fd485536664967d5ffad34b3184e7b63d0816d39.tar.gz | |
Merge "warn for no polymorphic identity w/ poly hierarchy" into main
Diffstat (limited to 'lib/sqlalchemy/orm')
| -rw-r--r-- | lib/sqlalchemy/orm/mapper.py | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index 36b97cf17..5d784498a 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -1224,10 +1224,27 @@ class Mapper( else: self.persist_selectable = self.local_table - if self.polymorphic_identity is not None and not self.concrete: - self._identity_class = self.inherits._identity_class - else: + if self.polymorphic_identity is None: + self._identity_class = self.class_ + + if self.inherits.base_mapper.polymorphic_on is not None: + util.warn( + "Mapper %s does not indicate a polymorphic_identity, " + "yet is part of an inheritance hierarchy that has a " + "polymorphic_on column of '%s'. Objects of this type " + "cannot be loaded polymorphically which can lead to " + "degraded or incorrect loading behavior in some " + "scenarios. Please establish a polmorphic_identity " + "for this class, or leave it un-mapped. " + "To omit mapping an intermediary class when using " + "declarative, set the '__abstract__ = True' " + "attribute on that class." + % (self, self.inherits.base_mapper.polymorphic_on) + ) + elif self.concrete: self._identity_class = self.class_ + else: + self._identity_class = self.inherits._identity_class if self.version_id_col is None: self.version_id_col = self.inherits.version_id_col |
