Skip to content

Bug: Using the API plugin, starlette throws AssertionError #65

@jklaise

Description

@jklaise

The dashboard works, but starlette throws on this line: https://github.com/Kludex/starlette/blob/49d4de92867cb38a781069701ad57cecab4a1a36/starlette/staticfiles.py#L91

Versions:

chancy==0.25.1
starlette==0.50.0
uvicorn==0.38.0

Code:

import asyncio

from chancy import Chancy, Queue, Worker
from chancy.plugins.api import Api
from chancy.plugins.api.auth import SimpleAuthBackend

auth = True
plugins = []

api = Api(
    authentication_backend=SimpleAuthBackend(
        {"admin": "password"},
    ),
    secret_key="my-secret-key",
)

if auth:
    plugins += [api]

chancy = Chancy(
    "postgresql://user.name@localhost:5432/db", plugins=plugins
)


async def main():
    async with chancy:
        # TODO: in prod run migrations separately
        await chancy.migrate()
        await chancy.declare(Queue("default"))
        async with Worker(chancy) as worker:
            await worker.wait_for_shutdown()


if __name__ == "__main__":
    asyncio.run(main())

Stack trace:

[2025-11-17 10:38:57][INFO] Started plugin 'Api'
[2025-11-17 10:38:57][INFO] Started plugin 'Leadership'
[2025-11-17 10:38:57][INFO] Started plugin 'Pruner'
[2025-11-17 10:38:57][INFO] Started plugin 'Recovery'
[2025-11-17 10:38:57][INFO] Started plugin 'Metrics'
[2025-11-17 10:38:57][INFO] Started plugin 'WorkflowPlugin'
[2025-11-17 10:38:57][INFO] Loading API sub-plugin workflow
[2025-11-17 10:38:57][INFO] Loading API sub-plugin base
[2025-11-17 10:38:57][INFO] Loading API sub-plugin metrics
[2025-11-17 10:38:57][INFO] Dashboard running at http://127.0.0.1:8000
[2025-11-17 10:38:57][INFO] Adding queue 'default' to worker using executor 'chancy.executors.process.ProcessExecutor'.
[2025-11-17 10:38:57][INFO] Started listening for realtime notifications.
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/Users/janis.klaise/git/chancy-test/.venv/lib/python3.13/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 244, in run_asgi
    result = await self.app(self.scope, self.asgi_receive, self.asgi_send)  # type: ignore[func-returns-value]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/janis.klaise/git/chancy-test/.venv/lib/python3.13/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/janis.klaise/git/chancy-test/.venv/lib/python3.13/site-packages/starlette/applications.py", line 107, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/Users/janis.klaise/git/chancy-test/.venv/lib/python3.13/site-packages/starlette/middleware/errors.py", line 151, in __call__
    await self.app(scope, receive, send)
  File "/Users/janis.klaise/git/chancy-test/.venv/lib/python3.13/site-packages/starlette/middleware/cors.py", line 77, in __call__
    await self.app(scope, receive, send)
  File "/Users/janis.klaise/git/chancy-test/.venv/lib/python3.13/site-packages/starlette/middleware/sessions.py", line 85, in __call__
    await self.app(scope, receive, send_wrapper)
  File "/Users/janis.klaise/git/chancy-test/.venv/lib/python3.13/site-packages/starlette/middleware/authentication.py", line 48, in __call__
    await self.app(scope, receive, send)
  File "/Users/janis.klaise/git/chancy-test/.venv/lib/python3.13/site-packages/starlette/middleware/exceptions.py", line 63, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/Users/janis.klaise/git/chancy-test/.venv/lib/python3.13/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    raise exc
  File "/Users/janis.klaise/git/chancy-test/.venv/lib/python3.13/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    await app(scope, receive, sender)
  File "/Users/janis.klaise/git/chancy-test/.venv/lib/python3.13/site-packages/starlette/routing.py", line 716, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/Users/janis.klaise/git/chancy-test/.venv/lib/python3.13/site-packages/starlette/routing.py", line 736, in app
    await route.handle(scope, receive, send)
  File "/Users/janis.klaise/git/chancy-test/.venv/lib/python3.13/site-packages/starlette/routing.py", line 462, in handle
    await self.app(scope, receive, send)
  File "/Users/janis.klaise/git/chancy-test/.venv/lib/python3.13/site-packages/starlette/staticfiles.py", line 91, in __call__
    assert scope["type"] == "http"
           ^^^^^^^^^^^^^^^^^^^^^^^
AssertionError

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions