Skip to content

Docker - the route "GET /docker/available-images/" returns 500 when image_name is empty or omitted #160

Description

@rapcmia

Describe the bug

This issue was noticed while checking trailing-slash behavior on the Docker routes on #159 . The exact documented route GET /docker/available-images/ returned a 500 Internal Server Error instead of a normal response, even though the schema shows image_name as an optional query parameter.

INFO:     172.18.0.1:43970 - "GET /openapi.json HTTP/1.1" 200 OK
15:15:52.299 GET /docker/available-images/
INFO:     172.18.0.1:47298 - "GET /docker/available-images/ HTTP/1.1" 500 Internal Server Error
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/fastapi/encoders.py", line 345, in jsonable_encoder
    data = dict(obj)
           ^^^^^^^^^
TypeError: 'socket' object is not iterable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/fastapi/encoders.py", line 350, in jsonable_encoder
    data = vars(obj)
           ^^^^^^^^^
TypeError: vars() argument must have __dict__ attribute

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/uvicorn/protocols/http/httptools_impl.py", line 421, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/uvicorn/middleware/proxy_headers.py", line 56, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/fastapi/applications.py", line 1159, in __call__

  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/opentelemetry/instrumentation/asgi/__init__.py", line 817, in __call__
    await self.app(scope, otel_receive, otel_send)
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/starlette/middleware/errors.py", line 186, in __call__
    raise exc
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/starlette/middleware/errors.py", line 164, in __call__
    await self.app(scope, receive, _send)
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/opentelemetry/instrumentation/fastapi/__init__.py", line 307, in __call__
    await self.app(scope, receive, send)
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/starlette/middleware/cors.py", line 88, in __call__
    await self.app(scope, receive, send)
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/starlette/middleware/exceptions.py", line 63, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    raise exc
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    await app(scope, receive, sender)
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
    await self.app(scope, receive, send)
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/starlette/routing.py", line 660, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/starlette/routing.py", line 680, in app
    await route.handle(scope, receive, send)
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/starlette/routing.py", line 276, in handle
    await self.app(scope, receive, send)
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/fastapi/routing.py", line 134, in app
    await wrap_app_handling_exceptions(app, request)(scope, receive, send)
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    raise exc
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    await app(scope, receive, sender)
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/fastapi/routing.py", line 120, in app
    response = await f(request)
               ^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/fastapi/routing.py", line 695, in app
    content = await serialize_response(
              ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/fastapi/routing.py", line 317, in serialize_response
    return jsonable_encoder(response_content)

    await self.app(scope, receive, send)
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/starlette/routing.py", line 660, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/starlette/routing.py", line 680, in app
    await route.handle(scope, receive, send)
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/starlette/routing.py", line 276, in handle
    await self.app(scope, receive, send)
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/fastapi/routing.py", line 134, in app
    await wrap_app_handling_exceptions(app, request)(scope, receive, send)
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    raise exc
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    await app(scope, receive, sender)
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/fastapi/routing.py", line 120, in app
    response = await f(request)
               ^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/fastapi/routing.py", line 695, in app
    content = await serialize_response(
              ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/fastapi/routing.py", line 317, in serialize_response
    return jsonable_encoder(response_content)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/fastapi/encoders.py", line 320, in jsonable_encoder
    jsonable_encoder(
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/fastapi/encoders.py", line 354, in jsonable_encoder
    return jsonable_encoder(
           ^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/fastapi/encoders.py", line 306, in jsonable_encoder
    encoded_value = jsonable_encoder(
                    ^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/fastapi/encoders.py", line 354, in jsonable_encoder
    return jsonable_encoder(
           ^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/fastapi/encoders.py", line 306, in jsonable_encoder
    encoded_value = jsonable_encoder(
                    ^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/fastapi/encoders.py", line 354, in jsonable_encoder
    return jsonable_encoder(
           ^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/fastapi/encoders.py", line 306, in jsonable_encoder
    encoded_value = jsonable_encoder(
                    ^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/fastapi/encoders.py", line 306, in jsonable_encoder
    encoded_value = jsonable_encoder(
                    ^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/fastapi/encoders.py", line 354, in jsonable_encoder
    return jsonable_encoder(
           ^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/fastapi/encoders.py", line 306, in jsonable_encoder
    encoded_value = jsonable_encoder(
                    ^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/fastapi/encoders.py", line 354, in jsonable_encoder
    return jsonable_encoder(
           ^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/fastapi/encoders.py", line 306, in jsonable_encoder
    encoded_value = jsonable_encoder(
                    ^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/fastapi/encoders.py", line 354, in jsonable_encoder
    return jsonable_encoder(
           ^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/fastapi/encoders.py", line 306, in jsonable_encoder
    encoded_value = jsonable_encoder(
                    ^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/fastapi/encoders.py", line 354, in jsonable_encoder
    return jsonable_encoder(
           ^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/fastapi/encoders.py", line 306, in jsonable_encoder
    encoded_value = jsonable_encoder(
                    ^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/fastapi/encoders.py", line 320, in jsonable_encoder
    jsonable_encoder(
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/fastapi/encoders.py", line 354, in jsonable_encoder
    return jsonable_encoder(
           ^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/fastapi/encoders.py", line 306, in jsonable_encoder
    encoded_value = jsonable_encoder(
                    ^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/fastapi/encoders.py", line 353, in jsonable_encoder
    raise ValueError(errors) from e
ValueError: [TypeError("'socket' object is not iterable"), TypeError('vars() argument must have __dict__ attribute')]

Retesting showed the handler works correctly when the image_name has a value like gateway or hummingbot, and also when a non-matching value returns an empty list. The issue only occurs when the query is empty or missing.

  • GET /docker/available-images/ -> 500 Internal Server Error
  • GET /docker/available-images/?image_name=gateway -> 200 OK
  • GET /docker/available-images/?image_name=hummingbot -> 200 OK
  • GET /docker/available-images/?image_name=zzzzzz -> 200 OK with []
  • API traceback: ValueError: [TypeError("'socket' object is not iterable"), TypeError('vars() argument must have __dict__ attribute')]

Steps to reproduce bug

  1. Start hummingbot-api and authenticate with the normal API credentials.
  2. Call GET /docker/available-images/ without an image_name query value.
  3. Observe that the route returns 500 Internal Server Error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions