_validate.py "RuntimeError: dictionary changed size during iteration"
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 24.4k
- Forks
- 2.3k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 13
Description
Environment
dash 2.17.1
dash-bootstrap-components 1.5.0
dash-bootstrap-templates 1.0.8
dash-core-components 2.0.0
dash-html-components 2.0.0
dash-loading-spinners 1.0.2
dash-table 5.0.0
Describe the bug
When starting a large Dash app (couple hundred callbacks, large callback chains) I receive the following error on startup and access to the application for the first time.
[2024-07-20 11:22:42,611] ERROR in app: Exception on /auth/dashboards/_dash-component-suites/dash/deps/react-dom@16.v2_17_1m1721474206.14.0.min.js [GET]
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1473, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 882, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 878, in full_dispatch_request
rv = self.preprocess_request()
File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1253, in preprocess_request
rv = self.ensure_sync(before_func)()
File "/usr/local/lib/python3.10/site-packages/dash/dash.py", line 1430, in _setup_server
_validate.validate_long_callbacks(self.callback_map)
File "/usr/local/lib/python3.10/site-packages/dash/_validate.py", line 528, in validate_long_callbacks
for callback in callback_map.values():
RuntimeError: dictionary changed size during iteration
This prevents the page from loading; however, I can perform a full refresh (ctrl-F5 on firefox) and everything will load correctly. This only occurs once, and only for the first user visiting the app. Occurs most times after starting the app. I have 1 callback which utilizes celery, but other than that no other long_callbacks in the app. Seems to occur more frequently when the overall number of callbacks increases in the application.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read dash/_validate.py around validate_long_callbacks and the _setup_server call in dash/dash.py; reproduce the first-request path with a large callback_map and a long callback. Done means the initial request no longer raises RuntimeError and the page loads without requiring a refresh.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- flask, python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100