cal-itp / benefits

Transit benefits enrollment, minus the paperwork.
https://docs.calitp.org/benefits
GNU Affero General Public License v3.0
25 stars 9 forks source link

Refactor(oauth): resolve RuntimeWarning #2152

Closed angela-tran closed 3 weeks ago

angela-tran commented 3 weeks ago

Closes #2003

The problem with calling register_providers in ready() is that it reads from the database (to get all the AuthProviders), but ready is called during management commands, so it is not entirely safe to interact with the database at that time.

This PR refactors the function to take one provider model object and moves it from ready() to the view where the OAuth client object is needed. The register method on BaseOAuth looks safe to call multiple times and returns a client object.

When reviewing

You should see that the RuntimeWarning no longer occurs when starting up the app (or running any management command - e.g. makemigrations, makemessages).

github-actions[bot] commented 3 weeks ago

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  benefits/oauth
  apps.py
  client.py
  views.py
Project Total  

This report was generated by python-coverage-comment-action

github-actions[bot] commented 3 weeks ago

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  benefits/oauth
  apps.py
  client.py
  views.py
Project Total  

This report was generated by python-coverage-comment-action

github-actions[bot] commented 3 weeks ago

Preview url: https://benefits-2152--cal-itp-previews.netlify.app