Skip to content

fix blueprint registering and double init#3798

Merged
T4rk1n merged 3 commits into
devfrom
fix/init-flask-run-command
May 29, 2026
Merged

fix blueprint registering and double init#3798
T4rk1n merged 3 commits into
devfrom
fix/init-flask-run-command

Conversation

@T4rk1n
Copy link
Copy Markdown
Contributor

@T4rk1n T4rk1n commented May 27, 2026

Fix #3787

@camdecoster camdecoster self-assigned this May 28, 2026
Comment thread dash/dash.py
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than add these blueprint checks for each backend, what if you add a check in init_app to see if the same server has already been registered? If the same server is passed in, then it becomes a no-op. If it's a new server, then the init takes place with the new server.

If you go with the current per backend approach, certain calls would add duplicate handlers or attempt to register the same routes again:

self.backend.before_request(self._setup_server)
...
self._setup_routes()

@sonarqubecloud
Copy link
Copy Markdown

Comment thread dash/backends/_quart.py
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could revert this change and get rid of this file from the PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asked Claude to write a test that would look at the idempotency when calling init twice. This might be worth adding:

def test_init_app_idempotent_on_same_server():
    external = Flask("ext")
    app = Dash(__name__, server=False)
    app.init_app(external)
    app.init_app(external)  # must not raise
    # request still works
    client = external.test_client()
    assert client.get("/").status_code == 200

@T4rk1n T4rk1n merged commit 715dae8 into dev May 29, 2026
30 of 31 checks passed
@T4rk1n T4rk1n deleted the fix/init-flask-run-command branch May 29, 2026 16:56
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

Successfully merging this pull request may close these issues.

[BUG] 4.2.0rc3 failure to lanch with flask run: ValueError: The name '_dash_assets' is already registered for a different blueprint.

2 participants