Skip to content

Fix callbacks registered twice under reload when Dash() gets an explicit name - #4053

Open
raashish1601 wants to merge 2 commits into
plotly:devfrom
raashish1601:fix/3912-alias-main-explicit-name
Open

raashish1601 wants to merge 2 commits into
plotly:devfrom
raashish1601:fix/3912-alias-main-explicit-name

Conversation

@raashish1601

@raashish1601 raashish1601 commented Oct 6, 2026 •

Copy link
Copy Markdown

Dash.__init__ passed caller_name to alias_main_module. When name is given, caller_name is that name. So Dash("myapp"), or Dash(__name__) inside an app factory module, never matched "__main__"/"__mp_main__". The alias was skipped, uvicorn's "repro:server" import ran the file again, and every callback was registered twice.

Now the alias uses get_caller_name(), the module that is actually running, whatever name is. The app name (caller_name) is unchanged. In the factory case the running module is the entry script that calls the factory, so that script gets aliased.

Tested:

  • Two new tests in tests/unit/test_main_module_alias.py: explicit name, and an app built by a factory called from the main module. Both fail on dev and pass here.
  • Ran the repro from the issue with uvicorn.run(..., reload=True). /_dash-dependencies lists output.children twice on dev, once with this change.
  • pytest tests/unit: the only failures are the test_pages.py path tests, test_pages_config.py and test_process_server_smoke. They fail the same way on dev on my Windows machine. pylint, flake8 and black pass on the changed files.

Contributor Checklist

  • I have broken down my PR scope into the following TODO tasks
    • Alias the running main module even when Dash() gets an explicit name
    • Add regression tests for the explicit-name and app-factory cases
  • I have run the tests locally and they passed. (refer to testing section in contributing)
  • I have added tests, or extended existing tests, to cover any new features or bugs fixed in this PR

optionals

  • I have added entry in the CHANGELOG.md

Fixes #3912

@sonarqubecloud

sonarqubecloud Bot commented Oct 6, 2026

Copy link
Copy Markdown

@raashish1601

Copy link
Copy Markdown
Author

The "Run performance benchmarks" failure isn't from this change. The benchmarks themselves report all within thresholds. The job then fails when it tries to post its results comment (HttpError: Resource not accessible by integration), since the PR comes from a fork. Dash Testing passed.

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] Callbacks still double-register with uvicorn --reload when an explicit name is passed to Dash() (incomplete fix for #3818 / #3883)

2 participants