kvesteri / sqlalchemy-continuum

Versioning extension for SQLAlchemy.
BSD 3-Clause "New" or "Revised" License
568 stars 128 forks source link

'enable_active_history' should exclude synonyms. SQLAlchemy 2.0 support issue #337

Open amnan98 opened 9 months ago

amnan98 commented 9 months ago

Please see here

configure_mappers() step throws AttributeError: '_ProxyImpl' object has no attribute 'dispatch' for synonyms because this code here:

https://github.com/kvesteri/sqlalchemy-continuum/blob/ccd87070baee40546f3289135e655ecf79b48cf8/sqlalchemy_continuum/builder.py#L194-L205

should also exclude synonyms. Additionally please review the SQLAlchemy 2.0 version of versioned history which does not require use of the private ".impl" attribute.

Code to reproduce error:

from datetime import datetime
from sqlalchemy import String, DateTime, Integer
from sqlalchemy.orm import (
    DeclarativeBase,
    Mapped,
    mapped_column,
    configure_mappers,
    declared_attr,
    synonym,
)
from sqlalchemy_continuum import make_versioned

make_versioned(user_cls=None)

class Base(DeclarativeBase):
    pass

class TableBase:
    id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
    create_time: Mapped[datetime] = mapped_column(DateTime(timezone=True))

    @declared_attr
    def createTime(cls):
        return synonym("create_time")

class A(Base, TableBase):
    __versioned__ = {}
    __tablename__ = "table_a"

    property_a: Mapped[str] = mapped_column(String)
    propA = synonym(property_a)

configure_mappers()