[Bug]: Registered script callbacks not cleared when reloading custom script bodies via settings
Is there an existing issue for this?
- [X] I have searched the existing issues and checked the recent builds/commits
What happened?
Lets say I have a script like this
# Other script code goes here etc
def on_save_imaged(image, p, fullfn, txt_fullfn):
print("lel")
script_callbacks.on_save_imaged(on_save_imaged)
Running that script once, that callback gets triggered and prints lel to the console
Now, change that print statement to print something else, go into settings, press Reload custom scriptbodies, and rerun that script
It will print both lel and whatever you changed the print to
You can keep doing this and it will just keep caching some non existent/no longer valid callback, and keep calling every single one
Steps to reproduce the problem
See the message above, or watch this https://vimeo.com/764938637
What should have happened?
Perhaps callbacks should be cleared upon reloading custom script bodies
Commit where the problem happens
3e15f8e
What platforms do you use to access UI ?
Windows
What browsers do you use to access the UI ?
Mozilla Firefox
Command Line Arguments
--medvram
Additional information, context and logs
No response
Seems to be rather easily resolved, by simply calling script_callbacks.clear_callbacks() inside reload_script_body_only() in scripts.py
edit: this solves the issue for me, but i am unsure if all callbacks are supposed to be cleared, perhaps you need to somehow filter and only clear callbacks which are registered from inside a script?
Regarding me referencing this issue in one of my commits, the commit above is wrong and this is the correct one instead https://github.com/AUTOMATIC1111/stable-diffusion-webui/commit/29692a359fe975399fe5633fbf9cff29f1d7d49c
Should definitely be investigated further by you guys
Closing as stale.