summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/decl_base.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2022-05-15 22:24:40 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2022-05-15 22:24:40 -0400
commitc05d3497aa3c6f8446e09c4201f270a0dc0626b8 (patch)
treef29ecdec2c8535b676dd476104265e8ef6a43cf2 /lib/sqlalchemy/orm/decl_base.py
parentc4dad3695f4ab9fef3a4cb05893492afbec811f7 (diff)
downloadsqlalchemy-c05d3497aa3c6f8446e09c4201f270a0dc0626b8.tar.gz
ensure MappedColumn col is mapped under alternate key
Fixes: #8025 Change-Id: I83ba54f05bd2e5fc87d80f42fbeb6d4d2f2ac5fa
Diffstat (limited to 'lib/sqlalchemy/orm/decl_base.py')
-rw-r--r--lib/sqlalchemy/orm/decl_base.py21
1 files changed, 14 insertions, 7 deletions
diff --git a/lib/sqlalchemy/orm/decl_base.py b/lib/sqlalchemy/orm/decl_base.py
index b1f81cb6b..fe5a20d04 100644
--- a/lib/sqlalchemy/orm/decl_base.py
+++ b/lib/sqlalchemy/orm/decl_base.py
@@ -876,20 +876,27 @@ class _ClassScanMapperConfig(_MapperConfig):
name_to_prop_key = collections.defaultdict(set)
for key, c in list(our_stuff.items()):
if isinstance(c, _MapsColumns):
- for col in c.columns_to_assign:
- if not isinstance(c, Composite):
- name_to_prop_key[col.name].add(key)
- declared_columns.add(col)
- # remove object from the dictionary that will be passed
- # as mapper(properties={...}) if it is not a MapperProperty
- # (i.e. this currently means it's a MappedColumn)
mp_to_assign = c.mapper_property_to_assign
if mp_to_assign:
our_stuff[key] = mp_to_assign
else:
+ # if no mapper property to assign, this currently means
+ # this is a MappedColumn that will produce a Column for us
del our_stuff[key]
+ for col in c.columns_to_assign:
+ if not isinstance(c, Composite):
+ name_to_prop_key[col.name].add(key)
+ declared_columns.add(col)
+
+ # if this is a MappedColumn and the attribute key we
+ # have is not what the column has for its key, map the
+ # Column explicitly under the attribute key name.
+ # otherwise, Mapper will map it under the column key.
+ if mp_to_assign is None and key != col.key:
+ our_stuff[key] = col
+
elif isinstance(c, Column):
# undefer previously occurred here, and now occurs earlier.
# ensure every column we get here has been named