lllyasviel / lllyasviel/stable-diffusion-webui-forge
(Forge and/or Gradio) Error Afflicting Many Extensions
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 13k
- Forks
- 1.7k
- PR merge metrics
- No merged PRs in 30d
Description
**Gradio 4** directly caused many extensions to have issues, due to code changes, deprecations, etc.
**Not this error.** This error is from Forge, and it affects many extensions.
### The error, which I'll refer to later as "Inherited Component bug":
```
File "C:\stable-diffusion-webui-forge\venv\lib\site-packages\gradio\components\base.py", line 118, in get_component_class_id
module_path = sys.modules[module_name].__file__
KeyError: 'extension-script-name.py'
```
---
Traceback Sample
```
*** Error calling: C:\stable-diffusion-webui-forge\extensions\--sd-webui-ar-plus\scripts\sd-webui-ar.py/ui
Traceback (most recent call last):
File "C:\stable-diffusion-webui-forge\modules\scripts.py", line 545, in wrap_call
return func(*args, **kwargs)
File "C:\stable-diffusion-webui-forge\extensions\--sd-webui-ar-plus\scripts\sd-webui-ar.py", line 261, in ui
ar_btns = [
File "C:\stable-diffusion-webui-forge\extensions\--sd-webui-ar-plus\scripts\sd-webui-ar.py", line 262, in
ARButton(ar=ar, value=label)
File "C:\stable-diffusion-webui-forge\extensions\--sd-webui-ar-plus\scripts\sd-webui-ar.py", line 35, in __init__
super().__init__(**kwargs)
File "C:\stable-diffusion-webui-forge\modules\ui_components.py", line 23, in __init__
super().__init__(*args, elem_classes=["tool", *elem_classes], value=value, **kwargs)
File "C:\stable-diffusion-webui-forge\modules\gradio_extensions.py", line 126, in __repaired_init__
original(self, *args, **fixed_kwargs)
File "C:\stable-diffusion-webui-forge\venv\lib\site-packages\gradio\component_meta.py", line 163, in wrapper
return fn(self, **kwargs)
File "C:\stable-diffusion-webui-forge\venv\lib\site-packages\gradio\components\button.py", line 61, in __init__
super().__init__(
File "C:\stable-diffusion-webui-forge\modules\gradio_extensions.py", line 35, in IOComponent_init
res = original_IOComponent_init(self, *args, **kwargs)
File "C:\stable-diffusion-webui-forge\venv\lib\site-packages\gradio\component_meta.py", line 163, in wrapper
return fn(self, **kwargs)
File "C:\stable-diffusion-webui-forge\venv\lib\site-packages\gradio\components\base.py", line 224, in __init__
self.component_class_id = self.__class__.get_component_class_id()
File "C:\stable-diffusion-webui-forge\venv\lib\site-packages\gradio\components\base.py", line 118, in get_component_class_id
module_path = sys.modules[module_name].__file__
KeyError: 'sd-webui-ar.py'
```
---
### What I believe Forge needs to Fix this Forge error:
- I may be wrong, the error may lie elsewhere.
- I believe [IOComponent_init](https://github.com/lllyasviel/stable-diffusion-webui-forge/blob/main/modules/gradio_extensions.py#L28) needs to be updated, or another function working with it.
---
### Reproduction:
Inherit from `ToolButton()` (or, presumably, **any** component imported from `modules.ui_components`).
```
from modules.ui_components import ToolButton
class CustomToolButton(ToolButton):
def __init__(self, value='button', **kwargs):
super().__init__(value, **kwargs)
self.value = value
def some_method(self):
pass
button = CustomToolButton(value='test')
```
---
### How extension developers can resolve the issue:
Note: developers are typically subclassing UI components so they can define class methods.
Therefore, this solution can be extremely painful/confusing depending on the application.
**Solution**: Do not subclass any UI components.
```
from modules.ui_components import ToolButton
button = ToolButton(value='test')
```
---
### What's happening:
Refer to the **Traceback Sample** in the accordion above.
**Strange Initialization for subclassed components:**
```
File "C:\stable-diffusion-webui-forge\modules\ui_components.py", line 23, in __init__
super().__init__(*args, elem_classes=["tool", *elem_classes], value=value, **kwargs)
```
**Important**: At this step, all WebUIs (A1111, Forge, Reforge, etc) experience **"Inherited Component bug"**
- "**Among other things**", **subclassed** component's have `.__module__` attribute value: "`extension-script-name`"
- Components which are **not** subclassed have `.__module__` attribute value: "`modules.ui_components`"
**WebUI Repairs Strange Initialization:**
```
File "C:\stable-diffusion-webui-forge\modules\gradio_extensions.py", line 126, in __repaired_init__
original(self, *args, **fixed_kwargs)
```
At this step, **all other WebUIs except Forge** successfully repair the Strange Initialization that occurs.
- "**Among other things**", `.__module__` attribute value: "`extension-script-name`" will be updated to "`modules.ui_components`"
---
### Hack that fixes the error, but not "Among other things":
"**Among other things**" (not resolved by this) includes the following:
- Button may initialize as `disabled` for no apparent reason
- "value" can be bugged resulting in a blank button
- These buttons seem to **completely ignore** any custom `.js` code defined by the script
- There could be much more strange behavior for different components defined like this
**This will make the script load in Forge:**
`CustomToolButton.__module__ = "modules.ui_components"`
**Example**:
```
from modules.ui_components import ToolButton
class CustomToolButton(ToolButton):
def __init__(self, value='button', **kwargs):
super().__init__(value, **kwargs)
self.value = value
def some_method(self):
pass
CustomToolButton.__module__ = "modules.ui_components"
button = CustomToolButton(value='test')
```
---
## What is the specific problem?!?!?!
**It has something to do with the patching steps when it tries "`__repaired_init__`"**
```
File "C:\stable-diffusion-webui-forge\venv\lib\site-packages\gradio\component_meta.py", line 163, in wrapper
return fn(self, **kwargs)
File "C:\stable-diffusion-webui-forge\venv\lib\site-packages\gradio\components\button.py", line 61, in __init__
super().__init__(
File "C:\stable-diffusion-webui-forge\modules\gradio_extensions.py", line 35, in IOComponent_init
res = original_IOComponent_init(self, *args, **kwargs)
File "C:\stable-diffusion-webui-forge\venv\lib\site-packages\gradio\component_meta.py", line 163, in wrapper
return fn(self, **kwargs)
```
**This in particular looks very suspicious to me**:
- There are many differences between `IOComponent` and `Component`
- `IOComponent_init()` is **identical** between [Forge](https://github.com/lllyasviel/stable-diffusion-webui-forge/blob/main/modules/gradio_extensions.py#L28) and [A1111](https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/master/modules/gradio_extensons.py#L17)
Contributor guide
No contributing guide indexed for this repository
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
Start with modules/gradio_extensions.py, especially IOComponent_init and __repaired_init__, then inspect modules/ui_components.py and the ToolButton inheritance path shown in the reproduction. Run the CustomToolButton example and compare the Forge implementation with the linked A1111 version. Done means subclassed components initialize without the reported KeyError and the described button behavior is preserved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100