I want to share some class level attributes among different declarative base classes in SQLAlchemy, such as type_annotation_map.
I tried the next:
from sqlalchemy import JSON
from sqlalchemy.orm import declared_attr, DeclarativeBase
class BaseMixin:
@declared_attr
def type_annotation_map(cls):
return {
list: JSON,
dict: JSON
}
class Base1(BaseMixin, DeclarativeBase):
pass
class Base2(BaseMixin, DeclarativeBase):
pass
Unfortunately, resulted in sqlalchemy.exc.ArgumentError when trying to map Python list type to corresponding SQLAlchemy Core type.