-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[BUG] Background callbacks with different outputs not working #2221
Comments
I have a very similar problem. In case this is useful, I have been using the following workaround for now. I do not know if the workaround breaks any other Dash functionality. In the file that defines the Dash app, I added: from dash.long_callback.managers import BaseLongCallbackManager
import uuid
def monkeypatched_hash_function(fn):
return uuid.uuid4()
BaseLongCallbackManager.hash_function = monkeypatched_hash_function |
But then it won't be cached, because every time the hash function is called it will return a different uuid. |
If I am not mistaken, the only time the hash function is called is when registering a function, and this is done only once per function (i.e., only once each time Dash's callback function is invoked). By looking at the code, it seems that the hash is only used as a key to then find the function that must be run when a certain callback is triggered. Thus, it seems that the only purpose of the hash is to assign a unique key each time a function is registered. Since I am not a Dash developer, I can of course be wrong, and please do let me know if I have misunderstood your issue. In any event, the workaround I proposed does work for me. |
Sorry, I meant that it wouldn't be cached between runs. If you restart the program, the uuids will be different. |
Thank you for fixing this issue! I recently ran into this exact problem, and it went away after I updated dash to the latest version. |
Describe your context
Please provide us your environment, so we can easily reproduce the issue.
pip list | grep dash
belowDescribe the bug
Background callbacks don't work if they are generated with a function/loop. For example, I've created a function
gen_callback
that creates a new callback given a css id.The background callback manager uses a hash function to know the key to get. This hash function just takes into account the code of the function, but not the variables used to generate that function.
dash/dash/long_callback/managers/__init__.py
Lines 101 to 105 in c897b2b
I think the hash should also take into account the
Output
list of the callback.Expected behavior
Using a variable as the id of one of the outputs creates multiple different, valid callbacks, that should work fine with background=True.
Possible temporary solution
Generate a function with
exec()
, replacing parts of a template code, and decorate the compiled function.The text was updated successfully, but these errors were encountered: