Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
amnan98 opened this issue Oct 9, 2023 · 0 comments

Comments

@amnan98
Copy link

amnan98 commented Oct 9, 2023

Please see here

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

def enable_active_history(self, version_classes):
"""
Assign all versioned attributes to use active history.
"""
for cls in version_classes:
for prop in sa.inspect(cls).iterate_properties:
if isinstance(prop, ConcreteInheritedProperty):
# ConcreteInheritedProperty doesn't have a dispatch, so we can't set active_history
continue
impl = getattr(cls, prop.key).impl
impl.active_history = True

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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant