Skip to content

Commit 6d3fe7d

Browse files
committed
fix(flask): avoid deprecated decorator before_first_request (#692)
Fixes Flask warning for the deprecation of the `before_first_request` decorator.
1 parent 091a9ed commit 6d3fe7d

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This file is part of REANA.
2-
# Copyright (C) 2017, 2018, 2019, 2020, 2021, 2022, 2023 CERN.
2+
# Copyright (C) 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024 CERN.
33
#
44
# REANA is free software; you can redistribute it and/or modify it
55
# under the terms of the MIT License; see LICENSE file for more details.

reana_server/ext.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@
1616
from reana_commons.config import REANA_LOG_FORMAT, REANA_LOG_LEVEL
1717
from werkzeug.exceptions import UnprocessableEntity
1818

19+
from invenio_oauthclient.signals import account_info_received
20+
from flask_security.signals import user_registered
21+
22+
1923
from reana_server import config
24+
from reana_server.utils import (
25+
_create_and_associate_local_user,
26+
_create_and_associate_oauth_user,
27+
)
2028

2129

2230
def handle_rate_limit_error(error: RateLimitExceeded):
@@ -75,6 +83,9 @@ def init_app(self, app):
7583
self.init_config(app)
7684
self.init_error_handlers(app)
7785

86+
account_info_received.connect(_create_and_associate_oauth_user)
87+
user_registered.connect(_create_and_associate_local_user)
88+
7889
@app.teardown_appcontext
7990
def shutdown_reana_db_session(response_or_exc):
8091
"""Close session on app teardown."""
@@ -85,20 +96,6 @@ def shutdown_reana_db_session(response_or_exc):
8596
invenio_db.session.remove()
8697
return response_or_exc
8798

88-
@app.before_first_request
89-
def connect_signals():
90-
"""Connect OAuthClient signals."""
91-
from invenio_oauthclient.signals import account_info_received
92-
from flask_security.signals import user_registered
93-
94-
from .utils import (
95-
_create_and_associate_local_user,
96-
_create_and_associate_oauth_user,
97-
)
98-
99-
account_info_received.connect(_create_and_associate_oauth_user)
100-
user_registered.connect(_create_and_associate_local_user)
101-
10299
def init_config(self, app):
103100
"""Initialize configuration."""
104101
for k in dir(config):

0 commit comments

Comments
 (0)