Skip to content

Commit

Permalink
Backport of #2359 for 0.64.x
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Jun 21, 2024
1 parent 6c941e3 commit 7aa4bf9
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion datasette/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ async def get(self, request):
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"]
Expand Down
4 changes: 2 additions & 2 deletions datasette/views/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async def data(self, request, default_labels=False, _size=None):
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(
Expand Down Expand Up @@ -226,7 +226,7 @@ async def data(
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:
Expand Down
6 changes: 3 additions & 3 deletions datasette/views/row.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async def data(self, request, default_labels=False):
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
Expand All @@ -38,14 +38,14 @@ async def data(self, request, default_labels=False):
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(
Expand Down
6 changes: 3 additions & 3 deletions datasette/views/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ async def post(self, request):
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
Expand Down Expand Up @@ -169,7 +169,7 @@ async def _data_traced(
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() -
Expand Down Expand Up @@ -204,7 +204,7 @@ async def gather(*args):

# 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(
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 @@ -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
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 @@ -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):
Expand Down

0 comments on commit 7aa4bf9

Please sign in to comment.