Skip to content

Cannot resolve fields from mixins #75

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

Closed
orsinium opened this issue Feb 21, 2019 · 4 comments
Closed

Cannot resolve fields from mixins #75

orsinium opened this issue Feb 21, 2019 · 4 comments
Labels

Comments

@orsinium
Copy link

The plugin can't find fields from mixins or abstract models.

class _UserMixin:
    some_field = s.Column(s.Integer)

class User(_UserMixin, Base):
    ...

User(some_field=1, ...)

Get error:

error: Unexpected column "some_field" for model "User"

Same error in this case:

class _UserBase(Base):
    __abstract__ = True
    some_field = s.Column(s.Integer)

class User(_UserBase):
    ...

User(some_field=1, ...)
@ilevkivskyi
Copy link
Contributor

I didn't include this in the initial implementation because I didn't think it is a widely used feature. This should be quite straightforward to implement, essentially as I understand we will need to collect columns from the whole MRO instead of just the model class body.

@orsinium
Copy link
Author

Thank you for your reply :) I personally don't like mixins, but there it is required because we have big batch of the same fields in the different models. We could avoid this through normalization, but this normalization would force us to use much of joins. It could slow down queries building (for developers) and execution (for database).

@MrSaints
Copy link

MrSaints commented Mar 7, 2019

I believe this affects polymorphic models too: https://docs.sqlalchemy.org/en/latest/orm/inheritance.html

ilevkivskyi pushed a commit that referenced this issue Jul 10, 2019
This addresses #75 by looking at all columns available in mro, not just topmost model.

It doesn't address the rest of the "mixins" story such as `declared_attr`.
@ilevkivskyi
Copy link
Contributor

Fixed by #80

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants