-
-
Notifications
You must be signed in to change notification settings - Fork 900
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
InvalidRequestError: Class does not have a __table__ or __tablename__ specified and does not inherit from an existing table-mapped class. #473
Comments
|
@davidism This does seem to be an issue. Using a tablename declared_attr from a 'mixin' does not work:
Results in the following test failure:
I do notice in the execution the following error is spawned:
Perhaps I'm using my name mixin wrong? |
@davidism it also appears that the solution that I had previously used in my own project, monkey patching _should_set_tablename with a lambda that always returns false, does not work any more and renders the following error:
|
@davidism @MichaelPereira
eliminates the problem. This isn't a desirable solution, however. |
The order of base classes has always been significant in Python, bases are scanned left to right. So I'm not going to consider that part a bug.
I'm fairly sure this issue has to do with their use of a completely separate |
@MichaelPereira did you have a chance to try out my initial suggestion? I'd like to know if this is actually a bug so I can work on 2.2.1 over the weekend. |
I'm quite sure it is a bug, it also fails in my application in this model - and no mixins are involved there: https://github.com/indico/indico/blob/master/indico/modules/events/registration/models/items.py |
I'm going to need a minimal example. These projects are nice but it's hard to trace what's going on. Just to confirm, you're saying this is a different bug, not a duplicate of the other Their base model class should look like from flask_sqlalchemy import Model as _BaseModel
# no as_declarative here, that's what make_declarative_base does
# or make_declarative_base should be overridden to return the as_declarative version
class Model(_BaseModel):
... |
@davidism thanks for looking into the problem. I'm sorry for not getting back earlier as we got swamped with the S3 outage in the meantime. I will try to get a reproducible example out of it since our tool is not open-source to help the resolution of the bug. |
@MichaelPereira oh, I was under the impression that your project was Flask-AppBuilder, since you linked to its source. The issue appears to be there, although an example is still useful. |
I contributed a little to it, but our project builds upon it. Anyway, if it's fixed for Flask-AppBuilder, it will be fixed for everyone using it :) It took me a few hours but I was able to get a reproducible error with just the bare minimum. Here are the steps:
About the make_declarative reference, I don't have enough knowledge to properly understand what it is doing but I know that Flask-AppBuilder defines it this way https://github.com/dpgaspar/Flask-AppBuilder/blob/master/flask_appbuilder/models/sqla/__init__.py#L23-L39 We had an issue with the number of argument, so we had to change it this same way in our project too: https://github.com/MichaelPereira/Flask-AppBuilder/pull/1/files#diff-d35cb966075d5560db04866a27e50fc8 Thanks again for your help and please let me know if I can be of more help |
Closing this as it seems to be an issue with Flask-AppBuilder, not directly related to the tablename issue. Check #541. |
Hi,
First of all congrats on the new release! This will allow us to go back to a pinned version of flask-sqlalchemy instead of the master branch 👍
On the other hand, the change #467 now generates this stack-trace in the Flask-AppBuilder project which I would need some help investigating to be able to use release 2.2 directly:
The error message contradicts the model declaration as it does have a
__tablename
defined:I understand that this change is related to the
@declared_attr
decorator but despite reading http://docs.sqlalchemy.org/en/latest/orm/extensions/declarative/api.html#api-reference I don't really know exactly how I should apply it to the model.Thanks for your help
The text was updated successfully, but these errors were encountered: