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

Add docs and example of using plain SQLAlchemy models with Flask-SQLAlchemy #791

Closed
wants to merge 2 commits into from

Conversation

e271828-
Copy link

There are many examples of people struggling to work around this limitation in flask-sqlalchemy, including various issues and PRs like:

#269
#250
#629

This PR documents a simple solution to bi-directional compatibility.

from flask_sqlalchemy import SQLAlchemy

# We can control this via `PLAIN_SQLALCHEMY_BASE=true python3 external_use.py`
PLAIN_SQLALCHEMY_BASE = "true" in os.getenv("PLAIN_SQLALCHEMY_BASE", "false").lower()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think runtime switching makes much sense for something like this...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think runtime switching makes much sense for something like this...

The obvious alternative is refactoring initialization to make model_class apply to generic models instead of only working properly (e.g. attaching query class) when flask_sqlalchemy.Model is subclassed.

Seems like people have been proposing patches to do that for several years, none of which have landed.

What would you suggest?

@davidism davidism added the docs label May 25, 2020
@davidism
Copy link
Member

davidism commented May 26, 2020

Closing for similar reasons to #629. This also seems overly complex. You can already use regular models with db.session.query(), and you can use Flask-SQLAlchemy outside a web app by doing app.app_context().push() first.

@davidism davidism closed this May 26, 2020
@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
Development

Successfully merging this pull request may close these issues.

3 participants