NicolasLM / spinach

Modern Redis task queue for Python 3
https://spinach.readthedocs.io
BSD 2-Clause "Simplified" License
63 stars 4 forks source link

Make Flask extension compatible with Flask>=2.2.0 #25

Closed bigjools closed 1 year ago

bigjools commented 1 year ago

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: https://github.com/NicolasLM/spinach/issues/24

NicolasLM commented 1 year ago

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