mblackgeo / flask-cognito-lib

A Flask extension that supports protecting routes with AWS Cognito following OAuth 2.1 best practices
https://mblackgeo.github.io/flask-cognito-lib/
MIT License
57 stars 15 forks source link

Fix deprecation warning: _app_ctx_stack -> g #19

Closed jak-sdk closed 1 year ago

jak-sdk commented 1 year ago

There are Flask deprecation warnings, this PR aims to update to the current approach recommended by Flask

======================================= warnings summary ========================================tests/test_decorators.py::test_cognito_login
tests/test_decorators.py::test_cognito_custom_state
tests/test_decorators.py::test_cognito_custom_scopes
tests/test_plugin.py::test_plugin_get_tokens
  /home/jak/code/flask-cognito-lib/src/flask_cognito_lib/plugin.py:70: DeprecationWarning: '_app_ctx_stack' is deprecated and will be removed in Flask 2.4. Use 'g' to store data, or 'app_ctx' to access the current context.
    ctx = ctx_stack.top

tests/test_decorators.py: 10 tests with warnings
  /home/jak/code/flask-cognito-lib/src/flask_cognito_lib/plugin.py:54: DeprecationWarning: '_app_ctx_stack' is deprecated and will be removed in Flask 2.4. Use 'g' to store data, or 'app_ctx' to access the current context.
    ctx = ctx_stack.top

I think I've used the right approach here, slightly hesitant to have removed the if ctx is not None: check, and wondering if it should be replaced by something like

with app.app_context():

Thanks, Jak

codecov-commenter commented 1 year ago

Codecov Report

Merging #19 (fd4b30b) into main (c493f07) will not change coverage. The diff coverage is 100.00%.

:exclamation: Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@            Coverage Diff            @@
##              main       #19   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            9         9           
  Lines          304       299    -5     
=========================================
- Hits           304       299    -5     
Impacted Files Coverage Δ
src/flask_cognito_lib/plugin.py 100.00% <100.00%> (ø)
mblackgeo commented 1 year ago

LGTM thanks. Think the recommendation is store in g now as you have done.