diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-09-21 17:55:39 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-09-21 17:57:38 -0400 |
| commit | 97b294093617eca7298a2fe97bd23bd6dc3b59bf (patch) | |
| tree | 87bafb6b1dec132f38b11eaf42eaee5a4dceb9c4 /lib/sqlalchemy | |
| parent | 930b07c3af5300e65473d44535db8c1d7133cb13 (diff) | |
| download | sqlalchemy-97b294093617eca7298a2fe97bd23bd6dc3b59bf.tar.gz | |
Ensure mapper.polymorphic_on is polymorphic_prop.columns[0]
Fixed bug where joined eager loading would fail for a polymorphically-
loaded mapper, where the polymorphic_on was set to an un-mapped
expression such as a CASE expression.
Change-Id: Iffe68196aaac592165c89684f09f4c06cd78ce54
Fixes: #3800
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/orm/mapper.py | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index b8dc5b8c3..60848097c 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -1401,9 +1401,6 @@ class Mapper(InspectionAttr): # polymorphic_on is a column that is already mapped # to a ColumnProperty prop = self._columntoproperty[self.polymorphic_on] - polymorphic_key = prop.key - self.polymorphic_on = prop.columns[0] - polymorphic_key = prop.key elif isinstance(self.polymorphic_on, MapperProperty): # polymorphic_on is directly a MapperProperty, # ensure it's a ColumnProperty @@ -1414,8 +1411,6 @@ class Mapper(InspectionAttr): "property or SQL expression " "can be passed for polymorphic_on") prop = self.polymorphic_on - self.polymorphic_on = prop.columns[0] - polymorphic_key = prop.key elif not expression._is_column(self.polymorphic_on): # polymorphic_on is not a Column and not a ColumnProperty; # not supported right now. @@ -1477,12 +1472,14 @@ class Mapper(InspectionAttr): col.label("_sa_polymorphic_on") key = col.key - self._configure_property( - key, - properties.ColumnProperty(col, - _instrument=instrument), - init=init, setparent=True) - polymorphic_key = key + prop = properties.ColumnProperty(col, _instrument=instrument) + self._configure_property(key, prop, init=init, setparent=True) + + # the actual polymorphic_on should be the first public-facing + # column in the property + self.polymorphic_on = prop.columns[0] + polymorphic_key = prop.key + else: # no polymorphic_on was set. # check inheriting mappers for one. |
