registry: _RegistryType
clsdict_view: _ClassDict
- collected_annotations: Dict[str, Tuple[Any, Any, Any, bool]]
+ collected_annotations: Dict[str, Tuple[Any, Any, Any, bool, Any]]
collected_attributes: Dict[str, Any]
local_table: Optional[FromClause]
persist_selectable: Optional[FromClause]
# acting like that for now.
if isinstance(obj, (Column, MappedColumn)):
- self._collect_annotation(name, annotation, True, obj)
# already copied columns to the mapped class.
continue
elif isinstance(obj, MapperProperty):
mapped_container,
mapped_anno,
is_dc,
+ attr_value,
) in self.collected_annotations.items()
)
]
for k, v in defaults.items():
setattr(self.cls, k, v)
+
self.cls.__annotations__ = annotations
self._assert_dc_arguments(dataclass_setup_arguments)
expect_mapped: Optional[bool],
attr_value: Any,
) -> Any:
+
+ if name in self.collected_annotations:
+ return self.collected_annotations[name][4]
+
if raw_annotation is None:
return attr_value
mapped_container,
extracted_mapped_annotation,
is_dataclass,
+ attr_value,
)
return attr_value
# 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
setattr(cls, name, obj)
elif isinstance(obj, (Column, MappedColumn)):
+
+ obj = self._collect_annotation(name, annotation, True, obj)
+
if attribute_is_overridden(name, obj):
# if column has been overridden
# (like by the InstrumentedAttribute of the
locally_collected_attributes[name] = copy_
setattr(cls, name, copy_)
+
return locally_collected_attributes
def _extract_mappable_attributes(self) -> None:
mapped_container,
extracted_mapped_annotation,
is_dataclass,
+ attr_value,
) = self.collected_annotations.get(
- k, (None, None, None, False)
+ k, (None, None, None, False, None)
)
value.declarative_scan(
self.registry,
from typing_extensions import Annotated
+from sqlalchemy import BigInteger
from sqlalchemy import Column
from sqlalchemy import exc
from sqlalchemy import ForeignKey
eq_(fas.args, ["self", "id"])
eq_(fas.kwonlyargs, ["data"])
+ def test_mapped_column_overrides(self, dc_decl_base):
+ """test #8688"""
+
+ class TriggeringMixin:
+ mixin_value: Mapped[int] = mapped_column(BigInteger)
+
+ class NonTriggeringMixin:
+ mixin_value: Mapped[int]
+
+ class Foo(dc_decl_base, TriggeringMixin):
+ __tablename__ = "foo"
+ id: Mapped[int] = mapped_column(primary_key=True, init=False)
+ foo_value: Mapped[float] = mapped_column(default=78)
+
+ class Bar(dc_decl_base, NonTriggeringMixin):
+ __tablename__ = "bar"
+ id: Mapped[int] = mapped_column(primary_key=True, init=False)
+ bar_value: Mapped[float] = mapped_column(default=78)
+
+ f1 = Foo(mixin_value=5)
+ eq_(f1.foo_value, 78)
+
+ b1 = Bar(mixin_value=5)
+ eq_(b1.bar_value, 78)
+
class RelationshipDefaultFactoryTest(fixtures.TestBase):
def test_list(self, dc_decl_base: Type[MappedAsDataclass]):