--- /dev/null
+.. change::
+ :tags: bug, mypy
+ :tickets: 6937
+
+ Fixed issue in mypy plugin where columns on a mixin would not be correctly
+ interpreted if the mapped class relied upon a ``__tablename__`` routine
+ that came from a superclass.
List[util.SQLAlchemyAttribute]
] = util.get_mapped_attributes(info, api)
+ # used by assign.add_additional_orm_attributes among others
+ util.establish_as_sqlalchemy(info)
+
if mapped_attributes is not None:
# ensure that a class that's mapped is always picked up by
# its mapped() decorator or declarative metaclass before
return None
+def establish_as_sqlalchemy(info: TypeInfo) -> None:
+ info.metadata.setdefault("sqlalchemy", {})
+
+
def set_is_base(info: TypeInfo) -> None:
_set_info_metadata(info, "is_base", True)
--- /dev/null
+# test #6937
+from sqlalchemy import Column
+from sqlalchemy import Integer
+from sqlalchemy.orm import declarative_base
+from sqlalchemy.orm import declared_attr
+from sqlalchemy.orm import Mapped
+
+
+Base = declarative_base()
+
+
+class UpdatedCls:
+ @declared_attr
+ def __tablename__(cls) -> Mapped[str]:
+ return cls.__name__.lower()
+
+ updated_at = Column(Integer)
+
+
+class Bar(UpdatedCls, Base):
+ id = Column(Integer(), primary_key=True)
+ num = Column(Integer)
+
+
+Bar.updated_at.in_([1, 2, 3])
+
+b1 = Bar(num=5, updated_at=6)