Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on OPTIONS request to database #1100

Closed
akehrer opened this issue Nov 20, 2020 · 2 comments
Closed

Error on OPTIONS request to database #1100

akehrer opened this issue Nov 20, 2020 · 2 comments
Labels

Comments

@akehrer
Copy link

akehrer commented Nov 20, 2020

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
@simonw simonw added the bug label Dec 3, 2020
@simonw
Copy link
Owner

simonw commented Dec 3, 2020

Replicated this against the live demo as well:

/tmp % curl -XOPTIONS https://latest.datasette.io/fixtures.json
{"ok": false, "error": "object Response can't be used in 'await' expression", "status": 500, "title": null}%                                                                                                                                  /tmp % 

@simonw simonw closed this as completed in a45a3df Dec 3, 2020
@simonw
Copy link
Owner

simonw commented Dec 3, 2020

Fixed in the demo:

% curl -XOPTIONS https://latest.datasette.io/fixtures.json
ok%

simonw added a commit that referenced this issue Dec 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants