summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2017-10-28 13:28:58 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2017-10-28 13:29:48 -0400
commitfd4289c5829d6498495ac59fe1dccb23b4975281 (patch)
tree23881bd839a6ca99d62748ef910fc1c343c5284c /lib/sqlalchemy
parentf7b957b589207cae98b6feec63be84ee6423c3ca (diff)
downloadsqlalchemy-fd4289c5829d6498495ac59fe1dccb23b4975281.tar.gz
Filter attributes we don't map during a load_scalar_attributes
Fixed bug where a descriptor that is elsewhere a mapped column or relationship within a hierarchy based on :class:`.AbstractConcreteBase` would be referred towards during a refresh operation, causing an error as the attribute is not mapped as a mapper property. A similar issue can arise for other attributes like the "type" column added by :class:`.AbstractConcreteBase` if the class fails to include "concrete=True" in its mapper, however the check here should also prevent that scenario from causing a problem. Change-Id: I407b07a3a3e2c374da19fc86ed44b987d595dcfa Fixes: #4124
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/orm/loading.py9
-rw-r--r--lib/sqlalchemy/orm/mapper.py1
2 files changed, 10 insertions, 0 deletions
diff --git a/lib/sqlalchemy/orm/loading.py b/lib/sqlalchemy/orm/loading.py
index cbc995489..a25a1422d 100644
--- a/lib/sqlalchemy/orm/loading.py
+++ b/lib/sqlalchemy/orm/loading.py
@@ -784,6 +784,15 @@ def load_scalar_attributes(mapper, state, attribute_names):
result = False
+ # in the case of inheritance, particularly concrete and abstract
+ # concrete inheritance, the class manager might have some keys
+ # of attributes on the superclass that we didn't actually map.
+ # These could be mapped as "concrete, dont load" or could be completely
+ # exluded from the mapping and we know nothing about them. Filter them
+ # here to prevent them from coming through.
+ if attribute_names:
+ attribute_names = attribute_names.intersection(mapper.attrs.keys())
+
if mapper.inherits and not mapper.concrete:
# because we are using Core to produce a select() that we
# pass to the Query, we aren't calling setup() for mapped
diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py
index 1d172f71a..31a93f42e 100644
--- a/lib/sqlalchemy/orm/mapper.py
+++ b/lib/sqlalchemy/orm/mapper.py
@@ -1143,6 +1143,7 @@ class Mapper(InspectionAttr):
self.inherits._inheriting_mappers.append(self)
self.passive_updates = self.inherits.passive_updates
self._all_tables = self.inherits._all_tables
+
for key, prop in mapper._props.items():
if key not in self._props and \
not self._should_exclude(key, key, local=False,