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

Flask plugin breaks DeclarativeBase #1361

Open
pvanderlinden opened this issue Jul 23, 2024 · 3 comments
Open

Flask plugin breaks DeclarativeBase #1361

pvanderlinden opened this issue Jul 23, 2024 · 3 comments

Comments

@pvanderlinden
Copy link

The plugin breaks the DeclarativeBase, e.g.:

from typing import Any

from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.orm import DeclarativeBase
from sqlalchemy.types import JSON

class Base(DeclarativeBase):
    type_annotation_map = {dict[str, Any]: JSON}
db = SQLAlchemy(model_class=Base)

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 with type_annotation_map and the type_annotation_map. This doesn't happen without the Flask plugin.

Environment:

  • Python version: 3.11.6
  • Flask-SQLAlchemy version: 3.1.1
  • SQLAlchemy version: 2.0.31
@samuelhwilliams
Copy link

Yep, I get the same - unsure what the right way around this is :(

@pamelafox
Copy link
Contributor

Are you able to use Flask-SQLAlchemy-Lite for your use case? https://flask-sqlalchemy-lite.readthedocs.io/en/latest/

@samuelhwilliams
Copy link

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.

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

No branches or pull requests

3 participants