Skip to content

Commit

Permalink
Fix for TableNotFound, refs #2359
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Jun 21, 2024
1 parent 6268611 commit 7316dd4
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
4 changes: 1 addition & 3 deletions datasette/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1628,9 +1628,7 @@ async def resolve_table(self, request):
if not table_exists:
is_view = await db.view_exists(table_name)
if not (table_exists or is_view):
raise TableNotFound(
"Table not found: {}".format(table_name), db.name, table_name
)
raise TableNotFound(db.name, table_name)
return ResolvedTable(db, table_name, is_view)

async def resolve_row(self, request):
Expand Down
4 changes: 2 additions & 2 deletions datasette/utils/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def __init__(self, database_name):


class TableNotFound(NotFound):
def __init__(self, message, database_name, table):
super().__init__(message)
def __init__(self, database_name, table):
super().__init__("Table not found")
self.database_name = database_name
self.table = table

Expand Down
10 changes: 5 additions & 5 deletions tests/test_api_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ async def test_insert_rows(ds_write, return_rows):
{},
None,
404,
["Table not found: docs2"],
["Table not found"],
),
(
"/data/docs/-/insert",
Expand Down Expand Up @@ -274,7 +274,7 @@ async def test_insert_rows(ds_write, return_rows):
{"rows": [{"title": "Test"}]},
None,
404,
["Table not found: badtable"],
["Table not found"],
),
# missing primary key
(
Expand Down Expand Up @@ -598,7 +598,7 @@ async def test_delete_row_errors(ds_write, scenario):
assert (
response.json()["errors"] == ["Permission denied"]
if scenario == "no_token"
else ["Table not found: bad_table"]
else ["Table not found"]
)
assert len((await ds_write.client.get("/data/docs.json?_shape=array")).json()) == 1

Expand Down Expand Up @@ -703,7 +703,7 @@ async def test_update_row_check_permission(ds_write, scenario):
assert (
response.json()["errors"] == ["Permission denied"]
if scenario == "no_token"
else ["Table not found: bad_table"]
else ["Table not found"]
)


Expand Down Expand Up @@ -830,7 +830,7 @@ async def test_drop_table(ds_write, scenario):
assert response.json()["ok"] is False
expected_error = "Permission denied"
if scenario == "bad_table":
expected_error = "Table not found: bad_table"
expected_error = "Table not found"
elif scenario == "immutable":
expected_error = "Database is immutable"
assert response.json()["errors"] == [expected_error]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_table_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async def test_table_json(ds_client):
async def test_table_not_exists_json(ds_client):
assert (await ds_client.get("/fixtures/blah.json")).json() == {
"ok": False,
"error": "Table not found: blah",
"error": "Table not found",
"status": 404,
"title": None,
}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_table_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ async def test_csv_json_export_links_include_labels_if_foreign_keys(ds_client):

@pytest.mark.asyncio
async def test_table_not_exists(ds_client):
assert "Table not found: blah" in (await ds_client.get("/fixtures/blah")).text
assert "Table not found" in (await ds_client.get("/fixtures/blah")).text


@pytest.mark.asyncio
Expand Down

0 comments on commit 7316dd4

Please sign in to comment.