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

Make Flask extension compatible with Flask>=2.2.0 #25

Merged
merged 1 commit into from
Oct 13, 2022

Conversation

bigjools
Copy link
Collaborator

Flask 2.2.0 deprecated the context stack in favour of using Python ContextVar, and introduced a fake stack for some sort of backward compatibility. However, it is not compatible enough for us as the existing code would blindly push context replacing any existing one, which will break application code.

The extension now does the recommended action of storing its data on flask.g - in this case we store the context that needs to be popped since _app_ctx_stack is deprecated.

There are no existing tests for this extension but I've tested it locally to my satisfaction.

Drive-by fix: Since Signals doesn't guarantee the order of callbacks, enable local callbacks for the job_started and job_finished signals so that users can be sure that the context was pushed.

Fixes: #24

Flask 2.2.0 deprecated the context stack in favour of using Python
ContextVar, and introduced a fake stack for some sort of backward
compatibility. However, it is not compatible enough for us as the
existing code would blindly push context replacing any existing
one, which will break application code.

The extension now does the recommended action of storing its data on
flask.g - in this case we store the context that needs to be popped
since _app_ctx_stack is deprecated.

There are no existing tests for this extension but I've tested it
locally to my satisfaction.

Fixes: NicolasLM#24
@NicolasLM
Copy link
Owner

It makes sense, thank you for taking care of this.

@NicolasLM NicolasLM merged commit ab6298e into NicolasLM:master Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Flask >= 2.2 breaks the Spinach extension
2 participants