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

Property names different from column names are not respected in inherited classes #245

Closed
killthekitten opened this issue May 3, 2020 · 0 comments

Comments

@killthekitten
Copy link
Contributor

When a declared_attr is defined in a child class of a versioned model, the corresponding version model doesn't pick up the name of the attribute. Instead, it defaults to the column name.

As a result, when the changeset is assigned to the version model, the changes in the declared_attr are not stored.

Here's some pseudo-code to illustrate the issue:

class SingleTableInheritanceTestCase(TestCase):
    def create_models(self):
        class TextItem(self.Model):
            ...
            id = sa.Column(sa.Integer, autoincrement=True, primary_key=True)

            discriminator = sa.Column(
                sa.Unicode(100)
            )

            __mapper_args__ = {
                'polymorphic_on': discriminator,
                'with_polymorphic': '*'
            }

        class Article(TextItem):
            __mapper_args__ = {'polymorphic_identity': u'article'}
            name = sa.Column(sa.Unicode(255))

            @declared_attr
            def status(cls):
                return sa.Column("_status", sa.Unicode(255))

    def test_declared_attr_inheritance(self):
        assert not self.ArticleVersion._status
        assert self.ArticleVersion.status

This is what Article.__mapper__._columntoproperty looks like in this case:

{Column('_status', Unicode(length=255), table=<text_item>): <ColumnProperty at 0x110689650; status>, ...}

I'm thinking of a fix that would change the build_model method to populate the version model with column_property based on the mapper of the original model. Would that make sense @kvesteri?

killthekitten added a commit to killthekitten/sqlalchemy-continuum that referenced this issue May 6, 2020
killthekitten added a commit to killthekitten/sqlalchemy-continuum that referenced this issue May 6, 2020
kvesteri added a commit that referenced this issue May 24, 2020
Fix #245: create column aliases in the version table
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