Skip to content

Flask-SQLAlchemy 3 compatibility #186

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

Merged
merged 5 commits into from
Oct 28, 2022

Conversation

Dosenpfand
Copy link
Contributor

Addresses #185, adds support for flask_sqlalchemy >= 3.0.0

@Dosenpfand Dosenpfand mentioned this pull request Oct 24, 2022
3 tasks
@@ -14,13 +14,10 @@
#)
#app.config['DEBUG_TB_HOSTS'] = ('127.0.0.1', '::1' )
app.config['SECRET_KEY'] = 'asd'

# TODO: This can be removed once flask_sqlalchemy 3.0 ships
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
Copy link
Contributor

@nickjj nickjj Oct 24, 2022

Choose a reason for hiding this comment

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

Should we keep this in as a comment with a callout for folks using SQLAlchemy 2.X?

Something like:

# This is no longer needed for Flask-SQLAlchemy 3.0+, if you're using 2.X you'll want to define this:
# app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

Copy link
Contributor Author

@Dosenpfand Dosenpfand Oct 24, 2022

Choose a reason for hiding this comment

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

Yes, probably the safer approach to leave it in. I re-added it here and in the test app.
Changed to your proposal for both test and example.

@nickjj
Copy link
Contributor

nickjj commented Oct 24, 2022

@davidism, do you have any last minute feedback before I merge this one in? Based on your PR's bullets I think it hits all of the marks.

@@ -95,6 +95,10 @@ def init_app(self, app):
"The Flask-DebugToolbar requires the 'SECRET_KEY' config "
"var to be set")

if not app.config.get("SQLALCHEMY_RECORD_QUERIES", False):
app.logger.warning(
"'SQLALCHEMY_RECORD_QUERIES' ist not set to True. SQL query logging will not be available.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: ist should be is

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@davidism
Copy link
Member

Looks good. You could set SQLALCHEMY_RECORD_QUERIES to True if debug mode is enabled during init_app. The user could always disable it again after that. But I wouldn't unconditionally enable it, that would be annoying if they still had the extension installed outside debug mode.

@nickjj
Copy link
Contributor

nickjj commented Oct 25, 2022

Thanks. If it defaults to true if debug mode is on, I wonder if we should remove this:

        if not app.config.get("SQLALCHEMY_RECORD_QUERIES", False):
            app.logger.warning(
                "'SQLALCHEMY_RECORD_QUERIES' is not set to True. SQL query logging will not be available.")

Because in theory DBT would expect debug mode to be enabled to function.

@Dosenpfand Dosenpfand requested a review from nickjj October 26, 2022 12:11
@Dosenpfand
Copy link
Contributor Author

I added SQLALCHEMY_RECORD_QUERIES to the default config and removed the warning.

@nickjj
Copy link
Contributor

nickjj commented Oct 28, 2022

Thanks, are you feeling good to merge this @Dosenpfand? I think it's ready.

@Dosenpfand
Copy link
Contributor Author

Yes @nickjj, looks good to me.

@nickjj
Copy link
Contributor

nickjj commented Oct 28, 2022

Thanks a lot for the contribution.

@nickjj nickjj merged commit b5a7c03 into pallets-eco:master Oct 28, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants