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

Re-display user's query with an error message if an error occurs #1346

Merged
merged 13 commits into from
Jun 2, 2021

Conversation

simonw
Copy link
Owner

@simonw simonw commented May 28, 2021

Refs #619

@simonw
Copy link
Owner Author

simonw commented May 28, 2021

The one test failure here actually illustrates a larger problem: if the user specifies .json?_shape=array but an error occurs, what should we do?

Prior to this change we return the following JSON:

{
    "ok": false,
    "error": "You did not supply a value for binding 1.",
    "status": 500,
    "title": null
}

But this comes from the handle_500 higher level code here:

datasette/datasette/app.py

Lines 1251 to 1263 in eae3084

info.update(
{
"ok": False,
"error": message,
"status": status,
"title": title,
}
)
headers = {}
if self.ds.cors:
headers["Access-Control-Allow-Origin"] = "*"
if request.path.split("?")[0].endswith(".json"):
await asgi_send_json(send, info, status=status, headers=headers)

@simonw
Copy link
Owner Author

simonw commented May 28, 2021

This is the current test failure, but it actually another problem that we don't have tests in place for errors with different formats and shapes:

    def test_magic_parameters_cannot_be_used_in_arbitrary_queries(magic_parameters_client):
        response = magic_parameters_client.get(
            "/data.json?sql=select+:_header_host&_shape=array"
        )
        assert 400 == response.status
>       assert "You did not supply a value for binding 1." == response.json["error"]
E       TypeError: list indices must be integers or slices, not str

The test fails because response.json here is the empty list [].

@codecov
Copy link

codecov bot commented Jun 2, 2021

Codecov Report

Merging #1346 (3bffc35) into main (7b106e1) will increase coverage by 0.14%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1346      +/-   ##
==========================================
+ Coverage   91.56%   91.71%   +0.14%     
==========================================
  Files          34       34              
  Lines        4282     4332      +50     
==========================================
+ Hits         3921     3973      +52     
+ Misses        361      359       -2     
Impacted Files Coverage Δ
datasette/app.py 95.69% <ø> (-0.15%) ⬇️
datasette/renderer.py 94.20% <100.00%> (+0.17%) ⬆️
datasette/utils/__init__.py 94.36% <100.00%> (+0.05%) ⬆️
datasette/views/base.py 95.41% <100.00%> (+0.39%) ⬆️
datasette/views/database.py 97.28% <100.00%> (+0.09%) ⬆️
datasette/views/table.py 95.90% <100.00%> (+0.07%) ⬆️
datasette/tracer.py 85.05% <0.00%> (+3.44%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7b106e1...3bffc35. Read the comment docs.

@simonw simonw marked this pull request as ready for review June 2, 2021 03:45
@simonw simonw merged commit 9552414 into main Jun 2, 2021
@simonw simonw deleted the query-errors branch June 2, 2021 03:46
@danp danp mentioned this pull request Sep 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant