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

Concrete Inheritance does not work properly #667

Closed
halfdan opened this issue Jan 26, 2019 · 2 comments
Closed

Concrete Inheritance does not work properly #667

halfdan opened this issue Jan 26, 2019 · 2 comments

Comments

@halfdan
Copy link

halfdan commented Jan 26, 2019

I'm trying to use concrete inheritance with flask-sqlalchemy but can't seem to get it to work. I've seen similar issues as the ones reportedly fixed by #541. At this point I'm not sure what else to try.

I uploaded my code to https://github.com/halfdan/flask-sqla-concrete-inheritance/blob/master/models.py

I'm essentially trying to get to a point where I can call db.session.query(ListItem) and get both CompanyListItems and GeoListItems properly loaded. This is documented here: https://docs.sqlalchemy.org/en/latest/orm/extensions/declarative/api.html#sqlalchemy.ext.declarative.AbstractConcreteBase

With the current code I'm getting

sqlalchemy.exc.InvalidRequestError: When initializing mapper Mapper|List|lists, expression 'ListItem' failed to locate a name ("name 'ListItem' is not defined"). If this is a class name, consider adding this relationship() to the <class 'models.List'> class after both dependent classes have been defined.

when trying to run l = List().

Thoughts?


untitled diagram

@davidism
Copy link
Member

I am not familiar with concrete inheritance. As stated in #248, I did not attempt to support it because there were no existing tests for it and no one had requested it in the past. Are you sure this is because of Flask-SQLAlchemy and not your code? Does it work in plain SQLAlchemy?

If you need this, I'm happy to review a patch, but I will not be actively working on it. The simple solution if it's really related to tablename generation is to set the tablenames manually, as you would have to in plain SQLAlchemy.

@halfdan
Copy link
Author

halfdan commented Jan 26, 2019

@davidism Hi there! Thanks for the quick reply - I managed to reproduce some part of the issue in raw SQLalchemy. Looks like there's some weird internal state that only gets set after CompanyItemList is instantiated at least once.

I'll take this issue over to SQLa and close the issue here.

@halfdan halfdan closed this as completed Jan 26, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants