diff options
author | mike bayer <mike_mp@zzzcomputing.com> | 2023-03-31 13:55:28 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@bbpush.zzzcomputing.com> | 2023-03-31 13:55:28 +0000 |
commit | db69e680da3aa01572c19cdedb6448e74a01c790 (patch) | |
tree | 4b711a0d7253656f6be1cff3034058c290d90914 /lib/sqlalchemy/orm/decl_base.py | |
parent | 90efd4480b07e2df04c3c1b3dd7917224757b64c (diff) | |
parent | b4c1f29413f678c43d03afdaedd18bd18b23d59a (diff) | |
download | sqlalchemy-db69e680da3aa01572c19cdedb6448e74a01c790.tar.gz |
Merge "skip anno-only mixin columns that are overridden on subclasses" into main
Diffstat (limited to 'lib/sqlalchemy/orm/decl_base.py')
-rw-r--r-- | lib/sqlalchemy/orm/decl_base.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/sqlalchemy/orm/decl_base.py b/lib/sqlalchemy/orm/decl_base.py index f59b1c90e..828501d8c 100644 --- a/lib/sqlalchemy/orm/decl_base.py +++ b/lib/sqlalchemy/orm/decl_base.py @@ -617,7 +617,7 @@ class _ClassScanMapperConfig(_MapperConfig): if not sa_dataclass_metadata_key: def attribute_is_overridden(key: str, obj: Any) -> bool: - return getattr(cls, key) is not obj + return getattr(cls, key, obj) is not obj else: @@ -974,7 +974,10 @@ class _ClassScanMapperConfig(_MapperConfig): # then test if this name is already handled and # otherwise proceed to generate. if not fixed_table: - assert name in collected_attributes + assert ( + name in collected_attributes + or attribute_is_overridden(name, None) + ) continue else: # here, the attribute is some other kind of @@ -1343,11 +1346,22 @@ class _ClassScanMapperConfig(_MapperConfig): # copy mixin columns to the mapped class for name, obj, annotation, is_dataclass in attributes_for_class(): + if ( not fixed_table and obj is None and _is_mapped_annotation(annotation, cls, originating_class) ): + # obj is None means this is the annotation only path + + if attribute_is_overridden(name, obj): + # perform same "overridden" check as we do for + # Column/MappedColumn, this is how a mixin col is not + # applied to an inherited subclass that does not have + # the mixin. the anno-only path added here for + # #9564 + continue + collected_annotation = self._collect_annotation( name, annotation, originating_class, True, obj ) |