I have a Flask 0.12.4 app and am using Flask-Admin.
I get this error intermittently when developing locally, and have just started seeing it in one of our public environments too.
AssertionError: A blueprint's name collision occurred between
<flask.blueprints.Blueprint object at 0x7f5cd31f96d0> and
<flask.blueprints.Blueprint object at 0x7f5cd33b0d90>.
Both share the same name "admin".
Blueprints that are created on the fly need unique names.
The steps to reproduce in my development environment are slightly odd:
form_columns
so it refers to a non-existent name)The line which is causing the error is this one:
# admin.py
admin = flask_admin.Admin(
app, index_view=MyIndexView(), template_mode="bootstrap3"
)
It seemed like the line in question was being called multiple times (although the file it's in is only imported in one place). I tried passing a custom endpoint
in the Admin
constructor and continued to get the same error but with the new endpoint name, which suggested that was the case.
This answer refers in passing to the same problem, and to the solution of using init_app
rather than passing the app
to the constructor.
Doing that, my code then looked like this, and the error went away:
# admin.py
# Notice I'm not passing app here any more.
admin = flask_admin.Admin(index_view=MyIndexView(), template_mode="bootstrap3")
# app.py
admin.init_app(app) # This line is new
I don't understand the detail of how the problem occurred or exactly why this solved it, so any further pointers welcome!