Fix UnboundLocalError in async background callbacks#3822
Open
i-murray wants to merge 2 commits into
Open
Conversation
In the async_run() path of the Celery and Diskcache background callback managers, user_callback_output was referenced after the try/except block without being initialised. When an async callback raised PreventUpdate or another exception, control skipped the assignment and the subsequent asyncio.iscoroutine(user_callback_output) check raised UnboundLocalError, masking the original error. Initialise user_callback_output to None before the try block and only evaluate the coroutine check when no error occurred. Add unit tests that exercise the generated job functions directly for the success, exception and PreventUpdate paths.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



In the
async_run()path of the Celery and Diskcache background callback managers,user_callback_outputwas referenced after the try/except block without being initialised. When an async callback raisedPreventUpdateor another exception, control skipped the assignment and the subsequentasyncio.iscoroutine(user_callback_output)check raisedUnboundLocalError, masking the original error.Initialise
user_callback_outputtoNonebefore the try block and only evaluate the coroutine check when no error occurred. Add unit tests that exercise the generated job functions directly for the success, exception andPreventUpdatepaths.Closes #3821
Contributor Checklist
dash/background_callback/managers/celery_manager.py&dash/background_callback/managers/diskcache_manager.pytests/unit/test_async_background_callback_job_fn.pyoptionals
CHANGELOG.md