Backport of #2359 for 0.64.x

This commit is contained in:
Simon Willison 2024-06-21 16:18:38 -07:00
commit 7aa4bf9506
6 changed files with 11 additions and 11 deletions

View file

@ -342,7 +342,7 @@ class DataView(BaseView):
try:
db = self.ds.get_database(route=database_route)
except KeyError:
raise NotFound("Database not found: {}".format(database_route))
raise NotFound("Database not found")
database = db.name
_format = request.url_vars["format"]

View file

@ -37,7 +37,7 @@ class DatabaseView(DataView):
try:
db = self.ds.get_database(route=database_route)
except KeyError:
raise NotFound("Database not found: {}".format(database_route))
raise NotFound("Database not found")
database = db.name
visible, private = await self.ds.check_visibility(
@ -226,7 +226,7 @@ class QueryView(DataView):
try:
db = self.ds.get_database(route=database_route)
except KeyError:
raise NotFound("Database not found: {}".format(database_route))
raise NotFound("Database not found")
database = db.name
params = {key: request.args.get(key) for key in request.args}
if "sql" in params:

View file

@ -19,7 +19,7 @@ class RowView(DataView):
try:
db = self.ds.get_database(route=database_route)
except KeyError:
raise NotFound("Database not found: {}".format(database_route))
raise NotFound("Database not found")
database = db.name
# Ensure user has permission to view this row
@ -38,14 +38,14 @@ class RowView(DataView):
try:
db = self.ds.get_database(route=database_route)
except KeyError:
raise NotFound("Database not found: {}".format(database_route))
raise NotFound("Database not found")
database = db.name
sql, params, pks = await _sql_params_pks(db, table, pk_values)
results = await db.execute(sql, params, truncate=True)
columns = [r[0] for r in results.description]
rows = list(results.rows)
if not rows:
raise NotFound(f"Record not found: {pk_values}")
raise NotFound(f"Record not found")
async def template_data():
display_columns, display_rows = await display_columns_and_rows(

View file

@ -96,7 +96,7 @@ class TableView(DataView):
try:
db = self.ds.get_database(route=database_route)
except KeyError:
raise NotFound("Database not found: {}".format(database_route))
raise NotFound("Database not found")
database_name = db.name
table_name = tilde_decode(request.url_vars["table"])
# Handle POST to a canned query
@ -169,7 +169,7 @@ class TableView(DataView):
try:
db = self.ds.get_database(route=database_route)
except KeyError:
raise NotFound("Database not found: {}".format(database_route))
raise NotFound("Database not found")
database_name = db.name
# We always now run queries sequentially, rather than with asyncio.gather() -
@ -204,7 +204,7 @@ class TableView(DataView):
# If table or view not found, return 404
if not is_view and not table_exists:
raise NotFound(f"Table not found: {table_name}")
raise NotFound(f"Table not found")
# Ensure user has permission to view this table
visible, private = await self.ds.check_visibility(

View file

@ -34,7 +34,7 @@ def test_table_json(app_client):
def test_table_not_exists_json(app_client):
assert {
"ok": False,
"error": "Table not found: blah",
"error": "Table not found",
"status": 404,
"title": None,
} == app_client.get("/fixtures/blah.json").json

View file

@ -520,7 +520,7 @@ def test_csv_json_export_links_include_labels_if_foreign_keys(app_client):
def test_table_not_exists(app_client):
assert "Table not found: blah" in app_client.get("/fixtures/blah").text
assert "Table not found" in app_client.get("/fixtures/blah").text
def test_table_html_no_primary_key(app_client):