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

Error when using polymorphic_on with CASE statement #25

Open
AbdealiLoKo opened this issue Oct 18, 2022 · 0 comments
Open

Error when using polymorphic_on with CASE statement #25

AbdealiLoKo opened this issue Oct 18, 2022 · 0 comments

Comments

@AbdealiLoKo
Copy link
Contributor

The polymorphic_on can be a CASE WHEN statement.
Ref: https://docs.sqlalchemy.org/en/14/orm/mapping_api.html#sqlalchemy.orm.mapper.params.polymorphic_on

But it looks like sqlalchemy-continuum fails when I try to add __versioned__ to a model with it.

  File "/home/abdealijk/venv/lib/python3.7/site-packages/sqlalchemy_continuum/builder.py", line 22, in check_reentry
    handler(*args, **kwargs)
  File "/home/abdealijk/venv/lib/python3.7/site-packages/sqlalchemy_continuum/builder.py", line 190, in configure_versioned_classes
    self.enable_active_history(pending_classes_copies)
  File "/home/abdealijk/venv/lib/python3.7/site-packages/sqlalchemy_continuum/builder.py", line 201, in enable_active_history
    getattr(cls, prop.key).impl.active_history = True
AttributeError: type object 'Writer' has no attribute '_sa_polymorphic_on'

Reproducible example:

from sqlalchemy import Column, Integer, String, case
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import configure_mappers
from sqlalchemy_continuum import make_versioned


make_versioned(user_cls=None)
Base = declarative_base()


class Writer(Base):
    __tablename__ = 'writer'
    __versioned__ = {}

    id = Column(Integer, primary_key=True)
    name = Column(String(255))
    type = Column(String(255))

    __mapper_args__ = {
        'polymorphic_on': (
            case(
                [(type.in_(['poet', 'lyricist']), 'bard')],
                else_=type,
            )
        ),
        'polymorphic_identity': 'writer',
    }


class Author(Base):
    __tablename__ = "author"
    __versioned__ = {}
    id = Column(Integer, primary_key=True)
    name = Column(String(255))

    __mapper_args__ = {
        'polymorphic_identity': 'author',
    }


configure_mappers()
indiVar0508 added a commit that referenced this issue Feb 6, 2023
doing a check for property key before enabling active_history
to make sure it can be directly accessed by parent_cls
@indiVar0508 indiVar0508 linked a pull request Feb 6, 2023 that will close this issue
indiVar0508 added a commit that referenced this issue Feb 6, 2023
doing a check for property key before enabling active_history
to make sure it can be directly accessed by parent_cls
indiVar0508 added a commit that referenced this issue Feb 16, 2023
doing a check for property key before enabling active_history
to make sure it can be directly accessed by parent_cls
indiVar0508 added a commit that referenced this issue Feb 16, 2023
doing a check for property key before enabling active_history
to make sure it can be directly accessed by parent_cls
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

Successfully merging a pull request may close this issue.

1 participant