Repository: Mikubill/sd-webui-controlnet (language: python)

Issue:
[Bug]: legacy_field_alias function bug
### Is there an existing issue for this?

- [X] I have searched the existing issues and checked the recent builds/commits of both this extension and the webui

### What happened?

when i try to submit a img2img api request, throw error:
    pydantic.error_wrappers.ValidationError: 1 validation error for ControlNetUnit
    low_vram
      value could not be parsed to a boolean (type=type_error.bool)

on file:
extensions\sd-webui-controlnet\internal_controlnet\args.py
on line 287:
params values is:
{'module': 'lineart_standard (from white bg & black line)', 'model': 'control_v11p_sd15_lineart_fp16 [5c23b17d]', 'weight': 0.6, 'lowvram': False, 'guidance_start': 0, 'guidance_end': 0.8, 'control_mode': 'ControlNet is more important', 'pixel_perfect': True}

on line 301:
params values is:
{'module': 'lineart_standard (from white bg & black line)', 'model': 'control_v11p_sd15_lineart_fp16 [5c23b17d]', 'weight': 0.6, 'lowvram': False, 'guidance_start': 0, 'guidance_end': 0.8, 'control_mode': 'ControlNet is more important', 'pixel_perfect': True, 'low_vram': 'lowvram'}

value['low_vram'] value is error

maybe the line 295 should be : 
values[key] = values[alias]


### Steps to reproduce the problem

1. submit img2img api request use by controlnet, set args low_vram: False.

### What should have happened?

process_images

### Commit where the problem happens

webui: img2img api
controlnet: use always_on_script args


### What browsers do you use to access the UI ?

Google Chrome

### Command Line Arguments

```Shell
"args": [
                "--listen",
                "--server-name",
                "192.168.178.138",
                "--port=7859",
                "--api",
                "--xformers",
                "--opt-channelslast",
                "--enable-insecure-extension-access",
                "--theme",
                "dark",
                "--skip-version-check",
                "--skip-python-version-check",
                "--skip-torch-cuda-test",
                "--skip-install",
            ]
```


### List of enabled extensions

No impact

### Console logs

```Shell
File "C:\sd-webui-aki-v4.6.1\modules\processing.py", line 845, in process_images
        res = process_images_inner(p)
      File "C:\sd-webui-aki-v4.6.1\extensions\sd-webui-controlnet\scripts\batch_hijack.py", line 56, in processing_process_images_hijack
        cn_is_batch, batches, output_dir, input_file_names = get_cn_batches(p)
      File "C:\sd-webui-aki-v4.6.1\extensions\sd-webui-controlnet\scripts\batch_hijack.py", line 196, in get_cn_batches
        units = external_code.get_all_units_in_processing(p)
      File "C:\sd-webui-aki-v4.6.1\extensions\sd-webui-controlnet\internal_controlnet\external_code.py", line 133, in get_all_units_in_processing
        return get_all_units(p.scripts, p.script_args)
      File "C:\sd-webui-aki-v4.6.1\extensions\sd-webui-controlnet\internal_controlnet\external_code.py", line 146, in get_all_units
        return get_all_units_from(script_args[cn_script.args_from : cn_script.args_to])
      File "C:\sd-webui-aki-v4.6.1\extensions\sd-webui-controlnet\internal_controlnet\external_code.py", line 174, in get_all_units_from
        all_units = [
        to_processing_unit(script_arg)
      File "C:\sd-webui-aki-v4.6.1\extensions\sd-webui-controlnet\internal_controlnet\external_code.py", line 228, in to_processing_unit
        return ControlNetUnit.from_dict(unit)
        return ControlNetUnit(**values)
      File "pydantic\main.py", line 341, in pydantic.main.BaseModel.__init__
    pydantic.error_wrappers.ValidationError: 1 validation error for ControlNetUnit
    low_vram
      value could not be parsed to a boolean (type=type_error.bool)
```


### Additional information

maybe the line 295 on the extensions\sd-webui-controlnet\internal_controlnet\args.py should be : 
values[key] = values[alias]


Discussion / hints:

Fix patch:
diff --git a/internal_controlnet/args.py b/internal_controlnet/args.py
index 50e32802e..a32ec5218 100644
--- a/internal_controlnet/args.py
+++ b/internal_controlnet/args.py
@@ -292,7 +292,7 @@ def legacy_field_alias(cls, values: dict) -> dict:
         for alias, key in ext_compat_keys.items():
             if alias in values:
                 assert key not in values, f"Conflict of field '{alias}' and '{key}'"
-                values[key] = alias
+                values[key] = values[alias]
                 cls.cls_logger.warn(
                     f"Deprecated alias '{alias}' detected. This field will be removed on 2024-06-01"
                     f"Please use '{key}' instead."


Test patch:
diff --git a/unit_tests/args_test.py b/unit_tests/args_test.py
index de9158220..af2529788 100644
--- a/unit_tests/args_test.py
+++ b/unit_tests/args_test.py
@@ -239,3 +239,7 @@ def test_infotext_parsing():
         pixel_perfect=True,
         control_mode="Balanced",
     ) == ControlNetUnit.parse(infotext)
+
+
+def test_alias():
+    ControlNetUnit.from_dict({"lowvram": True})