-
-
Notifications
You must be signed in to change notification settings - Fork 899
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
Flask plugin breaks DeclarativeBase #1361
Comments
Yep, I get the same - unsure what the right way around this is :( |
Are you able to use Flask-SQLAlchemy-Lite for your use case? https://flask-sqlalchemy-lite.readthedocs.io/en/latest/ |
Theoretically yes - but if that's the official advice it's probably be good to hear that and see this deprecated? If this is still being maintained then it feels like there should be an answer to this question. Switching to FSL is probably not a hard migration, but it's a chunk of work obviously still. And FSL is a very young lib in comparison. |
Hello everyone. I stumbled upon this issue myself, and found the following workaround (snippet from my codebase): db = SQLAlchemy()
db.Model.registry.update_type_annotation_map(
{
datetime: sa.DateTime(timezone=True),
dict[str, Any]: JSONB().with_variant(sa.JSON, "sqlite"),
uuid.UUID: UUID(as_uuid=True).with_variant(SQLiteUUID(), "sqlite"),
}
) This seems to solve the issue for me, hope it will help if anyone else is having this issue :) |
The plugin breaks the DeclarativeBase, e.g.:
Gives the error:
sqlalchemy.exc.InvalidRequestError: Declarative base class has both a 'registry' attribute and a type_annotation_map entry. Per-base type_annotation_maps are not supported. Please apply the type_annotation_map to this registry directly.
However,
type_annotation_map
is supported on the base, but by subclassing the base class (something which seems to be happening inside the plugin), it now detects both the registry created from the base class withtype_annotation_map
and thetype_annotation_map
. This doesn't happen without the Flask plugin.Environment:
The text was updated successfully, but these errors were encountered: