FastUI icon indicating copy to clipboard operation
FastUI copied to clipboard

demo code /docs Fetch error Internal Server Error /openapi.json

Open YiHuangDB opened this issue 1 year ago • 9 comments

Latest main code Reproduce: make dev http://localhost:8000/docs

INFO:     127.0.0.1:58664 - "GET /docs HTTP/1.1" 200 OK
INFO:     127.0.0.1:58664 - "GET /openapi.json HTTP/1.1" 500 Internal Server Error
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/home/ubuntu/FastUI/venv/lib/python3.10/site-packages/uvicorn/protocols/http/httptools_impl.py", line 426, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
  File "/home/ubuntu/FastUI/venv/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 84, in __call__
    return await self.app(scope, receive, send)
  File "/home/ubuntu/FastUI/venv/lib/python3.10/site-packages/fastapi/applications.py", line 1106, in __call__
    await super().__call__(scope, receive, send)
  File "/home/ubuntu/FastUI/venv/lib/python3.10/site-packages/starlette/applications.py", line 122, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/ubuntu/FastUI/venv/lib/python3.10/site-packages/starlette/middleware/errors.py", line 184, in __call__
    raise exc
  File "/home/ubuntu/FastUI/venv/lib/python3.10/site-packages/starlette/middleware/errors.py", line 162, in __call__
    await self.app(scope, receive, _send)
  File "/home/ubuntu/FastUI/venv/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 79, in __call__
    raise exc
  File "/home/ubuntu/FastUI/venv/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 68, in __call__
    await self.app(scope, receive, sender)
  File "/home/ubuntu/FastUI/venv/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 20, in __call__
    raise e
  File "/home/ubuntu/FastUI/venv/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 17, in __call__
    await self.app(scope, receive, send)
  File "/home/ubuntu/FastUI/venv/lib/python3.10/site-packages/starlette/routing.py", line 718, in __call__
    await route.handle(scope, receive, send)
  File "/home/ubuntu/FastUI/venv/lib/python3.10/site-packages/starlette/routing.py", line 276, in handle
    await self.app(scope, receive, send)
  File "/home/ubuntu/FastUI/venv/lib/python3.10/site-packages/starlette/routing.py", line 66, in app
    response = await func(request)
  File "/home/ubuntu/FastUI/venv/lib/python3.10/site-packages/fastapi/applications.py", line 1061, in openapi
    return JSONResponse(self.openapi())
  File "/home/ubuntu/FastUI/venv/lib/python3.10/site-packages/fastapi/applications.py", line 1033, in openapi
    self.openapi_schema = get_openapi(
  File "/home/ubuntu/FastUI/venv/lib/python3.10/site-packages/fastapi/openapi/utils.py", line 475, in get_openapi
    field_mapping, definitions = get_definitions(
  File "/home/ubuntu/FastUI/venv/lib/python3.10/site-packages/fastapi/_compat.py", line 227, in get_definitions
    field_mapping, definitions = schema_generator.generate_definitions(
  File "/home/ubuntu/FastUI/venv/lib/python3.10/site-packages/pydantic/json_schema.py", line 377, in generate_definitions
    self.generate_inner(schema)
  File "/home/ubuntu/FastUI/venv/lib/python3.10/site-packages/pydantic/json_schema.py", line 552, in generate_inner
    json_schema = current_handler(schema)
  File "/home/ubuntu/FastUI/venv/lib/python3.10/site-packages/pydantic/_internal/_schema_generation_shared.py", line 36, in __call__
    return self.handler(__core_schema)
  File "/home/ubuntu/FastUI/venv/lib/python3.10/site-packages/pydantic/json_schema.py", line 509, in handler_func
    json_schema = generate_for_schema_type(schema_or_field)
  File "/home/ubuntu/FastUI/venv/lib/python3.10/site-packages/pydantic/json_schema.py", line 1735, in definitions_schema
    self.generate_inner(definition)
  File "/home/ubuntu/FastUI/venv/lib/python3.10/site-packages/pydantic/json_schema.py", line 552, in generate_inner
    json_schema = current_handler(schema)
  File "/home/ubuntu/FastUI/venv/lib/python3.10/site-packages/pydantic/_internal/_schema_generation_shared.py", line 36, in __call__
    return self.handler(__core_schema)
  File "/home/ubuntu/FastUI/venv/lib/python3.10/site-packages/pydantic/json_schema.py", line 526, in new_handler_func
    json_schema = js_modify_function(schema_or_field, current_handler)
  File "/home/ubuntu/FastUI/src/python-fastui/fastui/components/__init__.py", line 188, in __get_pydantic_json_schema__
    json_schema['required'].append('links')
KeyError: 'required'

image

YiHuangDB avatar Dec 27 '23 18:12 YiHuangDB

Sorry I really can't read this, please format exceptions is a code block.

samuelcolvin avatar Dec 27 '23 18:12 samuelcolvin

sorry, updated with code block now. I tried to comments out json_schema['required'].append('links') line, the docs show but hungs after click individual api . image

Additional findings, it hungs like 1 minute or more then loaded successfully after comments out json_schema['required'].append('links') line, its not hungs forever, its just very very slow.

YiHuangDB avatar Dec 27 '23 18:12 YiHuangDB

The key error should be easy to fix.

The slow loading docs is a problem with the swagger frontend code - it can't copy with the recursive union which is the fundamental construct of FastUI components.

samuelcolvin avatar Dec 27 '23 18:12 samuelcolvin

See #58

samuelcolvin avatar Dec 27 '23 18:12 samuelcolvin

PR welcome to fix the key error.

samuelcolvin avatar Dec 27 '23 18:12 samuelcolvin

Cool. Thanks for sharing.

YiHuangDB avatar Dec 27 '23 18:12 YiHuangDB

I've limited knowledge as for now for fastui code. might take a while like months to reach my skill level to fix this issue. When I know how to fix I will fix it :-)

YiHuangDB avatar Dec 27 '23 18:12 YiHuangDB

It's a one line change, replace

json_schema['required'].append('links')

With

json_schema.setdefault('required', []).append('links')

samuelcolvin avatar Dec 27 '23 19:12 samuelcolvin

allright, let me test it, if works i will open pull request and follow up with test!

YiHuangDB avatar Dec 27 '23 22:12 YiHuangDB