-
Notifications
You must be signed in to change notification settings - Fork 81
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
SAWarning on EmailAddress #205
Comments
Thanks @Mogost, we haven't experienced this regression with our own project. |
@ticosax Apparently this is due to the fact that in my project there is a model class named
|
I'm sorry, that's not enough information for me. |
I'm pretty sure this occurs when you have different apps with the same model name. For example, if you have an app that defines a separate model named |
I'm not entirely sure how it gets triggered. It may be enough to run from sqlalchemy import MetaData
from aldjemy.orm import construct_models
construct_models(MetaData(schema="public")) Assuming your postgres database's schema is public. |
I don't think Aldjemy introspects the database, so I expect you should be able to produce the same result even if you use the incorrect schema name. |
I suspect the call to |
Yeah, I was able to confirm this. If you have models with the same name in two different apps, calling This is probably a bit difficult to resolve since it's a core difference between the Django ORM and SQLAlchemy. The core question is how do you generate the SQLAlchemy models for the following models?
One option would be to return the sqlalchemy models with the table names rather than the Django object names. That way you know they'd be unique. Another would be to return them as their app model name: |
I'd be surprised to learn that SQLAlchemy assumes that there will never be a model name conflict, so that leads me to think that whatever property from SQLAlchemy this is being keyed off of is being misused by Aldjemy. I'd suspect that whatever field that is should likely be based on the table name. |
You're correct. The error does indicate it's attempting to use the module. I couldn't quickly find where that's being set. Given the example below says
|
Oh, that's interesting. I wonder if we can modify the classname we generate for the Aldjemy model to something better. That might be a challenge for some of the auto-generated models for many-to-many through tables. Do you have an example project you can put on GitHub for me to reproduce? |
Nope, but if you add a model named |
Here's the warning I got: [...]/aldjemy/orm.py:165: SAWarning: This declarative base already contains a class with the same class name and module name as aldjemy.orm.Group, and will be replaced in the string-lookup table. |
Yep, that's the one. |
Yes exactly. I have only one EmailAddress model in my project. But I have the django-allauth app installed, which also has an EmailAddress model. |
Thanks for the quick change @ryanhiebert! |
You bet! Thanks, @tim-schilling , for making it easy to reproduce and giving me some really good hints! |
Probably after 150353d
django 3.2
aldjemy 2.3
The text was updated successfully, but these errors were encountered: