summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/decl_base.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2022-03-02 11:51:57 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2022-03-02 11:51:57 -0500
commit3fd1a52794c5463854fe36cbe97595d8489bbf62 (patch)
tree12597527384eb3af4a0866a52e89d4e0bce58fd6 /lib/sqlalchemy/orm/decl_base.py
parentafb9634fb28b00c7b0979660e3e0bfed6caafde5 (diff)
downloadsqlalchemy-3fd1a52794c5463854fe36cbe97595d8489bbf62.tar.gz
prevent Mapped[] auto-column logic w/ fixed table
When a class has __table__, people will still want to annotate the attributes on classes, so make sure a Mapped annotation without a right side is only interpreted as a column if there is no __table__ Change-Id: I7da4b4c43c4d2c8b6834b781569cb551e75b57b1
Diffstat (limited to 'lib/sqlalchemy/orm/decl_base.py')
-rw-r--r--lib/sqlalchemy/orm/decl_base.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/sqlalchemy/orm/decl_base.py b/lib/sqlalchemy/orm/decl_base.py
index 5c72371b2..3fb8af80c 100644
--- a/lib/sqlalchemy/orm/decl_base.py
+++ b/lib/sqlalchemy/orm/decl_base.py
@@ -498,6 +498,7 @@ class _ClassScanMapperConfig(_MapperConfig):
mapper_args_fn = None
table_args = inherited_table_args = None
tablename = None
+ fixed_table = "__table__" in clsdict_view
attribute_is_overridden = self._cls_attr_override_checker(self.cls)
@@ -666,7 +667,8 @@ class _ClassScanMapperConfig(_MapperConfig):
is_dataclass,
)
if obj is None:
- collected_attributes[name] = MappedColumn()
+ if not fixed_table:
+ collected_attributes[name] = MappedColumn()
else:
collected_attributes[name] = obj
else:
@@ -701,7 +703,11 @@ class _ClassScanMapperConfig(_MapperConfig):
annotation,
False,
)
- if obj is None and _is_mapped_annotation(annotation, cls):
+ if (
+ obj is None
+ and not fixed_table
+ and _is_mapped_annotation(annotation, cls)
+ ):
collected_attributes[name] = MappedColumn()
elif name in clsdict_view:
collected_attributes[name] = obj