Repository: AUTOMATIC1111/stable-diffusion-webui

Issue:
[Bug]: GET /sdapi/v1/options returns 500
### Is there an existing issue for this?

- [X] I have searched the existing issues and checked the recent builds/commits

### What happened?

When I started the webui with --nowebui and send a get request to `/sdapi/v1/options`, the response is 500. Error message is below
```shell
    pydantic.error_wrappers.ValidationError: 1 validation error for Options
    response -> sd_model_checkpoint
      value is not None (type=type_error.not_none)
```

### Steps to reproduce the problem

1. git clone the repo 
2. Run `python3.10 -m venv venv`
3. Run `source venv/bin/activate`
4. Run `COMMANDLINE_ARGS="--listen --xformers --skip-torch-cuda-test --nowebui" ./webui.sh`
5. Run `curl -X 'GET' 'http://localhost:7861/sdapi/v1/options' -H 'accept: application/json'`

### What should have happened?

Return 200 with a json file.

### Version or Commit where the problem happens

1.4.1

### What Python version are you running on ?

Python 3.10.x

### What platforms do you use to access the UI ?

Linux

### What device are you running WebUI on?

Nvidia GPUs (RTX 20 above)

### Cross attention optimization

xformers

### What browsers do you use to access the UI ?

_No response_

### Command Line Arguments

```Shell
--listen --xformers --skip-torch-cuda-test --nowebui
```


### List of extensions

None

### Console logs

```Shell
*** API error: GET: http://127.0.0.1:7861/sdapi/v1/options {'error': 'ValidationError', 'detail': '', 'body': '', 'errors': '1 validation error for Options\nresponse -> sd_model_checkpoint\n  value is not None (type=type_error.not_none)'}
    Traceback (most recent call last):
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/anyio/streams/memory.py", line 98, in receive
        return self.receive_nowait()
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/anyio/streams/memory.py", line 93, in receive_nowait
        raise WouldBlock
    anyio.WouldBlock

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/base.py", line 78, in call_next
        message = await recv_stream.receive()
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/anyio/streams/memory.py", line 118, in receive
        raise EndOfStream
    anyio.EndOfStream

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "/xxx/stable-diffusion-webui/modules/api/api.py", line 153, in exception_handling
        return await call_next(request)
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/base.py", line 84, in call_next
        raise app_exc
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/base.py", line 70, in coro
        await self.app(scope, receive_or_disconnect, send_no_error)
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/base.py", line 108, in __call__
        response = await self.dispatch_func(request, call_next)
      File "/xxx/stable-diffusion-webui/modules/api/api.py", line 117, in log_and_time
        res: Response = await call_next(req)
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/base.py", line 84, in call_next
        raise app_exc
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/base.py", line 70, in coro
        await self.app(scope, receive_or_disconnect, send_no_error)
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/cors.py", line 84, in __call__
        await self.app(scope, receive, send)
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/gzip.py", line 24, in __call__
        await responder(scope, receive, send)
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/gzip.py", line 44, in __call__
        await self.app(scope, receive, self.send_with_gzip)
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 79, in __call__
        raise exc
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 68, in __call__
        await self.app(scope, receive, sender)
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in __call__
        raise e
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
        await self.app(scope, receive, send)
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/routing.py", line 718, in __call__
        await route.handle(scope, receive, send)
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/routing.py", line 276, in handle
        await self.app(scope, receive, send)
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/routing.py", line 66, in app
        response = await func(request)
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/fastapi/routing.py", line 255, in app
        content = await serialize_response(
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/fastapi/routing.py", line 141, in serialize_response
        raise ValidationError(errors, field.type_)
    pydantic.error_wrappers.ValidationError: 1 validation error for Options
    response -> sd_model_checkpoint
      value is not None (type=type_error.not_none)
```


### Additional information

* NVIDIA driver 535.54.03
* CUDA Version: V12.2.91

I didn't edit any file in the local repo. I printed out `OptionsModel` and found `'sd_model_checkpoint': <class 'NoneType'>` in it. The value should be `string`.

The problem was cause by `"sd_model_checkpoint": OptionInfo(None, "Stable Diffusion checkpoint", gr.Dropdown, lambda: {"choices": list_checkpoint_tiles()}, refresh=refresh_checkpoints)`, and was fixed after I changed the `None` to `""`. The `/sdapi/v1/options` started returning the correct json.

[Bug]: GET /sdapi/v1/options returns 500
### Is there an existing issue for this?

- [X] I have searched the existing issues and checked the recent builds/commits

### What happened?

When I started the webui with --nowebui and send a get request to `/sdapi/v1/options`, the response is 500. Error message is below
```shell
    pydantic.error_wrappers.ValidationError: 1 validation error for Options
    response -> sd_model_checkpoint
      value is not None (type=type_error.not_none)
```

### Steps to reproduce the problem

1. git clone the repo 
2. Run `python3.10 -m venv venv`
3. Run `source venv/bin/activate`
4. Run `COMMANDLINE_ARGS="--listen --xformers --skip-torch-cuda-test --nowebui" ./webui.sh`
5. Run `curl -X 'GET' 'http://localhost:7861/sdapi/v1/options' -H 'accept: application/json'`

### What should have happened?

Return 200 with a json file.

### Version or Commit where the problem happens

1.4.1

### What Python version are you running on ?

Python 3.10.x

### What platforms do you use to access the UI ?

Linux

### What device are you running WebUI on?

Nvidia GPUs (RTX 20 above)

### Cross attention optimization

xformers

### What browsers do you use to access the UI ?

_No response_

### Command Line Arguments

```Shell
--listen --xformers --skip-torch-cuda-test --nowebui
```


### List of extensions

None

### Console logs

```Shell
*** API error: GET: http://127.0.0.1:7861/sdapi/v1/options {'error': 'ValidationError', 'detail': '', 'body': '', 'errors': '1 validation error for Options\nresponse -> sd_model_checkpoint\n  value is not None (type=type_error.not_none)'}
    Traceback (most recent call last):
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/anyio/streams/memory.py", line 98, in receive
        return self.receive_nowait()
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/anyio/streams/memory.py", line 93, in receive_nowait
        raise WouldBlock
    anyio.WouldBlock

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/base.py", line 78, in call_next
        message = await recv_stream.receive()
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/anyio/streams/memory.py", line 118, in receive
        raise EndOfStream
    anyio.EndOfStream

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "/xxx/stable-diffusion-webui/modules/api/api.py", line 153, in exception_handling
        return await call_next(request)
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/base.py", line 84, in call_next
        raise app_exc
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/base.py", line 70, in coro
        await self.app(scope, receive_or_disconnect, send_no_error)
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/base.py", line 108, in __call__
        response = await self.dispatch_func(request, call_next)
      File "/xxx/stable-diffusion-webui/modules/api/api.py", line 117, in log_and_time
        res: Response = await call_next(req)
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/base.py", line 84, in call_next
        raise app_exc
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/base.py", line 70, in coro
        await self.app(scope, receive_or_disconnect, send_no_error)
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/cors.py", line 84, in __call__
        await self.app(scope, receive, send)
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/gzip.py", line 24, in __call__
        await responder(scope, receive, send)
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/gzip.py", line 44, in __call__
        await self.app(scope, receive, self.send_with_gzip)
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 79, in __call__
        raise exc
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 68, in __call__
        await self.app(scope, receive, sender)
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in __call__
        raise e
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
        await self.app(scope, receive, send)
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/routing.py", line 718, in __call__
        await route.handle(scope, receive, send)
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/routing.py", line 276, in handle
        await self.app(scope, receive, send)
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/routing.py", line 66, in app
        response = await func(request)
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/fastapi/routing.py", line 255, in app
        content = await serialize_response(
      File "/xxx/stable-diffusion-webui/venv/lib/python3.10/site-packages/fastapi/routing.py", line 141, in serialize_response
        raise ValidationError(errors, field.type_)
    pydantic.error_wrappers.ValidationError: 1 validation error for Options
    response -> sd_model_checkpoint
      value is not None (type=type_error.not_none)
```


### Additional information

* NVIDIA driver 535.54.03
* CUDA Version: V12.2.91

I didn't edit any file in the local repo. I printed out `OptionsModel` and found `'sd_model_checkpoint': <class 'NoneType'>` in it. The value should be `string`.

The problem was cause by `"sd_model_checkpoint": OptionInfo(None, "Stable Diffusion checkpoint", gr.Dropdown, lambda: {"choices": list_checkpoint_tiles()}, refresh=refresh_checkpoints)`, and was fixed after I changed the `None` to `""`. The `/sdapi/v1/options` started returning the correct json.



Discussion:

Resolving patch:
diff --git a/modules/shared.py b/modules/shared.py
--- a/modules/shared.py
+++ b/modules/shared.py
@@ -409,7 +409,7 @@ def list_samplers():
 }))
 
 options_templates.update(options_section(('sd', "Stable Diffusion"), {
-    "sd_model_checkpoint": OptionInfo(None, "Stable Diffusion checkpoint", gr.Dropdown, lambda: {"choices": list_checkpoint_tiles()}, refresh=refresh_checkpoints),
+    "sd_model_checkpoint": OptionInfo("", "Stable Diffusion checkpoint", gr.Dropdown, lambda: {"choices": list_checkpoint_tiles()}, refresh=refresh_checkpoints),
     "sd_checkpoint_cache": OptionInfo(0, "Checkpoints to cache in RAM", gr.Slider, {"minimum": 0, "maximum": 10, "step": 1}),
     "sd_vae_checkpoint_cache": OptionInfo(0, "VAE Checkpoints to cache in RAM", gr.Slider, {"minimum": 0, "maximum": 10, "step": 1}),
     "sd_vae": OptionInfo("Automatic", "SD VAE", gr.Dropdown, lambda: {"choices": shared_items.sd_vae_items()}, refresh=shared_items.refresh_vae_list).info("choose VAE model: Automatic = use one with same filename as checkpoint; None = use VAE from checkpoint"),


Test patch: