Skip to content

Commit

Permalink
Fix UserWarning on Flask 2.2.0
Browse files Browse the repository at this point in the history
Flask 2.2.0 issues a warning if a url rule is added to a blueprint after it
has been registered, so this commit ensures that the documentation rules
are added before the blueprint is registered.

Fixes: python-restx#485

Signed-off-by: Jonathan Dieter <jonathan.dieter@spearline.com>
  • Loading branch information
jdieter committed Dec 14, 2022
1 parent 4c748d0 commit a4e7f28
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions flask_restx/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ def init_app(self, app, **kwargs):
# If app is a blueprint, defer the initialization
try:
app.record(self._deferred_blueprint_init)
self._register_specs(app)
self._register_doc(app)
# Flask.Blueprint has a 'record' attribute, Flask.Api does not
except AttributeError:
self._init_app(app)
Expand All @@ -245,9 +247,6 @@ def _init_app(self, app):
:param flask.Flask app: The flask application object
"""
self._register_specs(self.blueprint or app)
self._register_doc(self.blueprint or app)

app.handle_exception = partial(self.error_router, app.handle_exception)
app.handle_user_exception = partial(
self.error_router, app.handle_user_exception
Expand Down

0 comments on commit a4e7f28

Please sign in to comment.