Skip to content

Commit

Permalink
fix(flask): avoid deprecated decorator before_first_request (reanah…
Browse files Browse the repository at this point in the history
…ub#692)

Fixes Flask warning for the deprecation of the `before_first_request`
decorator.
  • Loading branch information
mdonadoni committed Jul 23, 2024
1 parent 397874a commit fed7ef2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This file is part of REANA.
# Copyright (C) 2017, 2018, 2019, 2020, 2021, 2022, 2023 CERN.
# Copyright (C) 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024 CERN.
#
# REANA is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
Expand Down
25 changes: 11 additions & 14 deletions reana_server/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@
from reana_commons.config import REANA_LOG_FORMAT, REANA_LOG_LEVEL
from werkzeug.exceptions import UnprocessableEntity

from invenio_oauthclient.signals import account_info_received
from flask_security.signals import user_registered


from reana_server import config
from reana_server.utils import (
_create_and_associate_local_user,
_create_and_associate_oauth_user,
)


def handle_rate_limit_error(error: RateLimitExceeded):
Expand Down Expand Up @@ -75,6 +83,9 @@ def init_app(self, app):
self.init_config(app)
self.init_error_handlers(app)

account_info_received.connect(_create_and_associate_oauth_user)
user_registered.connect(_create_and_associate_local_user)

@app.teardown_appcontext
def shutdown_reana_db_session(response_or_exc):
"""Close session on app teardown."""
Expand All @@ -85,20 +96,6 @@ def shutdown_reana_db_session(response_or_exc):
invenio_db.session.remove()
return response_or_exc

@app.before_first_request
def connect_signals():
"""Connect OAuthClient signals."""
from invenio_oauthclient.signals import account_info_received
from flask_security.signals import user_registered

from .utils import (
_create_and_associate_local_user,
_create_and_associate_oauth_user,
)

account_info_received.connect(_create_and_associate_oauth_user)
user_registered.connect(_create_and_associate_local_user)

def init_config(self, app):
"""Initialize configuration."""
for k in dir(config):
Expand Down

0 comments on commit fed7ef2

Please sign in to comment.