lllyasviel / lllyasviel/stable-diffusion-webui-forge
[Bug]/[Question]: Cache writer exception when dumping. Safe to ignore?
- Dominant language
- Python
- Stars
- 13k
- Forks
- 1.7k
- PR merge metrics
- No merged PRs in 30d
Description
### Checklist
- [X] The issue exists after disabling all extensions
- [ ] The issue exists on a clean installation of webui
- [ ] The issue is caused by an extension, but I believe it is caused by a bug in the webui
- [X] The issue exists in the current version of the webui
- [X] The issue has not been reported before recently
- [ ] The issue has been reported before but has not been fixed yet
### What happened?
I'm having problems with a specific Lora causing an error with the json.dump function due to encoding.
It raises an exception when running `json.dump(cache_data, file, indent=4, ensure_ascii=False)` in line 35 inside `modules/cache.py`:
```
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\threading.py", line 1016, in _bootstrap_inner
self.run()
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\threading.py", line 953, in run
self._target(*self._args, **self._kwargs)
File "D:\Stable Diffusion\stable-diffusion-webui-forge\modules\cache.py", line 35, in thread_func
json.dump(cache_data, file, indent=4, ensure_ascii=False)
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\json\__init__.py", line 180, in dump
fp.write(chunk)
UnicodeEncodeError: 'utf-8' codec can't encode characters in position 3-4: surrogates not allowed
```
I think I have identified the culprit, some keys inside `ss_dataset_dirs` from this Lora: https://civitai.com/models/374922
Here is some data from the Lora (extracted using https://xypher7.github.io/lora-metadata-viewer/):
```
"1_\udcd1\udce6": {
"n_repeats": 1,
"img_count": 500
},
"1_Բ\udcc9\udcf1": {
"n_repeats": 1,
"img_count": 728
},
"1_\udcb6\udcf1ħ\udcd1\udce6": {
"n_repeats": 1,
"img_count": 514
}
```
For now I just removed it and the error seems to be gone. But either way, would that even gonna cause any problems besides rebuilding the cache each launch?... If it doesn't I might as well just keep it, otherwise I could look into implementing a fix.
### Steps to reproduce the problem
1. Download this Lora: https://civitai.com/models/374922
2. Add it to your Lora folder
3. Run webui
4. Check the console
### What should have happened?
Cache file should have been written until the end. It freezes after reading that part of the Lora metadata.
### What browsers do you use to access the UI ?
Google Chrome
### Sysinfo
-
### Console logs
```Shell
Already added relevant logs above.
```
### Additional information
_No response_
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at modules/cache.py line 35 and reproduce the failure with the linked LoRA and its malformed metadata keys. Determine how the cache writer should handle these surrogate characters and verify that cache writing completes without the UnicodeEncodeError or startup freeze.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100