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

blueprint already registered #44

Open
inktrap opened this issue Jul 15, 2021 · 6 comments
Open

blueprint already registered #44

inktrap opened this issue Jul 15, 2021 · 6 comments

Comments

@inktrap
Copy link

inktrap commented Jul 15, 2021

I get this warning that will become an error:

UserWarning: The name 'foobar' is already registered for this blueprint. Use 'name=' to provide a unique name. This will become an error in Flask 2.1.
  self.register_blueprint(blueprint, **kw)

I checked out the source and in main.py app_factory() calls app.add_blueprint_list(). However, flask-security also tries to register all blueprints. Since flask's add_blueprint() method doesn't check wether a blueprint is already registered or not, it is attempted to register the same blueprints twice.

You can not unregister a blueprint:

The downside is that you cannot unregister a blueprint once an application was created without having to destroy the whole application object.

Who should fix this? add_blueprint is a part of flask … should every caller implement their own logic to check if a blueprint was already registered?

@iamhazel
Copy link

Ugh I didn't realize this could happen, that's frustrating. How would you even "destroy the whole application object"?

@inktrap
Copy link
Author

inktrap commented Apr 21, 2022

Obviously with app.destroy()

No just kidding, but there is a teardown_appcontext() which "Registers a function to be called when the application context ends. These functions are typically also called when the request context is popped."

But destroying the app-context wouldn't be the solution to this anyways … so I don't know if we are overlooking something more fundamental? Maybe we can ask for help?

So funny when old GitHub issues pop up and your issue-context got destroyed and you have to recreate it again ;P glad you replied :)

@iamhazel
Copy link

Obviously with app.destroy()

No just kidding, but there is a teardown_appcontext() which "Registers a function to be called when the application context ends. These functions are typically also called when the request context is popped."

But destroying the app-context wouldn't be the solution to this anyways … so I don't know if we are overlooking something more fundamental? Maybe we can ask for help?

So funny when old GitHub issues pop up and your issue-context got destroyed and you have to recreate it again ;P glad you replied :)

This is all a bit above my head tbh. I just want to name my blueprints what I want 😂 I didn't realize anything is "persistent" when you stop and re-run the application.

@inktrap
Copy link
Author

inktrap commented Apr 24, 2022 via email

@italomaia
Copy link
Owner

Can you show a minimal example? add_blueprint_list is not called by flask-security.

@jbhanks
Copy link

jbhanks commented Apr 30, 2022

I seem to be having this problem too. I was getting this error on some nested blueprints (which in my code are only explicitly registered once). I came across this and removed flask_login, and that stopped the error. I'm still not sure what is going on exactly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants