mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Fix for TableNotFound, refs #2359
This commit is contained in:
parent
62686114ee
commit
7316dd4ac6
5 changed files with 10 additions and 12 deletions
|
|
@ -1628,9 +1628,7 @@ class Datasette:
|
||||||
if not table_exists:
|
if not table_exists:
|
||||||
is_view = await db.view_exists(table_name)
|
is_view = await db.view_exists(table_name)
|
||||||
if not (table_exists or is_view):
|
if not (table_exists or is_view):
|
||||||
raise TableNotFound(
|
raise TableNotFound(db.name, table_name)
|
||||||
"Table not found: {}".format(table_name), db.name, table_name
|
|
||||||
)
|
|
||||||
return ResolvedTable(db, table_name, is_view)
|
return ResolvedTable(db, table_name, is_view)
|
||||||
|
|
||||||
async def resolve_row(self, request):
|
async def resolve_row(self, request):
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,8 @@ class DatabaseNotFound(NotFound):
|
||||||
|
|
||||||
|
|
||||||
class TableNotFound(NotFound):
|
class TableNotFound(NotFound):
|
||||||
def __init__(self, message, database_name, table):
|
def __init__(self, database_name, table):
|
||||||
super().__init__(message)
|
super().__init__("Table not found")
|
||||||
self.database_name = database_name
|
self.database_name = database_name
|
||||||
self.table = table
|
self.table = table
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -140,7 +140,7 @@ async def test_insert_rows(ds_write, return_rows):
|
||||||
{},
|
{},
|
||||||
None,
|
None,
|
||||||
404,
|
404,
|
||||||
["Table not found: docs2"],
|
["Table not found"],
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"/data/docs/-/insert",
|
"/data/docs/-/insert",
|
||||||
|
|
@ -274,7 +274,7 @@ async def test_insert_rows(ds_write, return_rows):
|
||||||
{"rows": [{"title": "Test"}]},
|
{"rows": [{"title": "Test"}]},
|
||||||
None,
|
None,
|
||||||
404,
|
404,
|
||||||
["Table not found: badtable"],
|
["Table not found"],
|
||||||
),
|
),
|
||||||
# missing primary key
|
# missing primary key
|
||||||
(
|
(
|
||||||
|
|
@ -598,7 +598,7 @@ async def test_delete_row_errors(ds_write, scenario):
|
||||||
assert (
|
assert (
|
||||||
response.json()["errors"] == ["Permission denied"]
|
response.json()["errors"] == ["Permission denied"]
|
||||||
if scenario == "no_token"
|
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
|
assert len((await ds_write.client.get("/data/docs.json?_shape=array")).json()) == 1
|
||||||
|
|
||||||
|
|
@ -703,7 +703,7 @@ async def test_update_row_check_permission(ds_write, scenario):
|
||||||
assert (
|
assert (
|
||||||
response.json()["errors"] == ["Permission denied"]
|
response.json()["errors"] == ["Permission denied"]
|
||||||
if scenario == "no_token"
|
if scenario == "no_token"
|
||||||
else ["Table not found: bad_table"]
|
else ["Table not found"]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -830,7 +830,7 @@ async def test_drop_table(ds_write, scenario):
|
||||||
assert response.json()["ok"] is False
|
assert response.json()["ok"] is False
|
||||||
expected_error = "Permission denied"
|
expected_error = "Permission denied"
|
||||||
if scenario == "bad_table":
|
if scenario == "bad_table":
|
||||||
expected_error = "Table not found: bad_table"
|
expected_error = "Table not found"
|
||||||
elif scenario == "immutable":
|
elif scenario == "immutable":
|
||||||
expected_error = "Database is immutable"
|
expected_error = "Database is immutable"
|
||||||
assert response.json()["errors"] == [expected_error]
|
assert response.json()["errors"] == [expected_error]
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ async def test_table_json(ds_client):
|
||||||
async def test_table_not_exists_json(ds_client):
|
async def test_table_not_exists_json(ds_client):
|
||||||
assert (await ds_client.get("/fixtures/blah.json")).json() == {
|
assert (await ds_client.get("/fixtures/blah.json")).json() == {
|
||||||
"ok": False,
|
"ok": False,
|
||||||
"error": "Table not found: blah",
|
"error": "Table not found",
|
||||||
"status": 404,
|
"status": 404,
|
||||||
"title": None,
|
"title": None,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -535,7 +535,7 @@ async def test_csv_json_export_links_include_labels_if_foreign_keys(ds_client):
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_table_not_exists(ds_client):
|
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
|
@pytest.mark.asyncio
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue