Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starting with Flask version 2.2.0, there's a UserWarning raised for Blueprint #485

Closed
morpheus65535 opened this issue Nov 7, 2022 · 2 comments · Fixed by #500
Closed
Labels
bug Something isn't working

Comments

@morpheus65535
Copy link

Starting with Flask version 2.2.0, there's a UserWarning raised for Blueprint. It will raise an exception in 2.3.0. With Flask 2.1.3, there's no warning.

Code

from flask import Flask, Blueprint
from flask_restx import Api

app = Flask(__name__)
api_bp = Blueprint('api', __name__)
api = Api(api_bp)
app.register_blueprint(api_bp, url_prefix="/api")


@app.route('/')
def hello_world():
    return 'Hello World!'


if __name__ == '__main__':
    app.run()

Repro Steps (if applicable)

  1. Create a basic API with code provided
  2. Run the code
  3. Check output

Expected Behavior

flask-restx should use Flask method properly to prevent it from getting broken in future.

Actual Behavior

Flask raise UserWarning.

Error Messages/Stack Trace

/Users/morpheus/Desktop/flask-restx-issue/venv/lib/python3.10/site-packages/flask_restx/api.py:322: UserWarning: The setup method 'add_url_rule' can no longer be called on the blueprint 'api'. It has already been registered at least once, any changes will not be applied consistently.
Make sure all imports, decorators, functions, etc. needed to set up the blueprint are done before registering it.
This warning will become an exception in Flask 2.3.
  app_or_blueprint.add_url_rule(self._doc, "doc", self.render_doc)
/Users/morpheus/Desktop/flask-restx-issue/venv/lib/python3.10/site-packages/flask/blueprints.py:490: UserWarning: The setup method 'record' can no longer be called on the blueprint 'api'. It has already been registered at least once, any changes will not be applied consistently.
Make sure all imports, decorators, functions, etc. needed to set up the blueprint are done before registering it.
This warning will become an exception in Flask 2.3.
  self.record(
/Users/morpheus/Desktop/flask-restx-issue/venv/lib/python3.10/site-packages/flask_restx/api.py:323: UserWarning: The setup method 'add_url_rule' can no longer be called on the blueprint 'api'. It has already been registered at least once, any changes will not be applied consistently.
Make sure all imports, decorators, functions, etc. needed to set up the blueprint are done before registering it.
This warning will become an exception in Flask 2.3.
  app_or_blueprint.add_url_rule(self.prefix or "/", "root", self.render_root)

Environment

  • Python version 3.10.2
  • Flask version 2.2.2
  • Flask-RESTX version 1.0.3
  • Other installed Flask extensions

Additional Context

This is your last chance to provide any pertinent details, don't let this opportunity pass you by!

@morpheus65535 morpheus65535 added the bug Something isn't working label Nov 7, 2022
@marcorichetta
Copy link

Relevant issue pallets/flask#4571

@jessereich-mcs
Copy link

jessereich-mcs commented Nov 20, 2022

Just getting around to investigating this warning. Any thoughts on how to properly register these blueprints?

jdieter added a commit to cyara/flask-restx that referenced this issue Dec 14, 2022
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>
jdieter added a commit to cyara/flask-restx that referenced this issue Dec 14, 2022
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>
jdieter added a commit to cyara/flask-restx that referenced this issue Jan 11, 2023
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>
peter-doggart pushed a commit that referenced this issue Jan 14, 2023
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: #485

Signed-off-by: Jonathan Dieter <jonathan.dieter@spearline.com>

Signed-off-by: Jonathan Dieter <jonathan.dieter@spearline.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants