Skip to content

Error on OPTIONS request to database #1100

@akehrer

Description

@akehrer

When I perform an OPTIONS request against a database or table datasette fails with an internal error.

All these tests result in the traceback below.

curl -XOPTIONS http://127.0.0.1:8001/test-db
curl -XOPTIONS http://127.0.0.1:8001/test-db/table1
curl -XOPTIONS http://127.0.0.1:8001/test-db/table1\?_search\=test
Traceback (most recent call last):
  File "[path-to-python]/site-packages/datasette/app.py", line 1033, in route_path
    response = await view(request, send)
  File "[path-to-python]/site-packages/datasette/views/base.py", line 146, in view
    request, **request.scope["url_route"]["kwargs"]
  File "[path-to-python]/site-packages/datasette/views/base.py", line 118, in dispatch_request
    return await handler(request, *args, **kwargs)
TypeError: object Response can't be used in 'await' expression

Making the options function in the DataView class async fixed it for me.

    async def options(self, request, *args, **kwargs):
        r = Response.text("ok")
        if self.ds.cors:
            r.headers["Access-Control-Allow-Origin"] = "*"
        return r

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions