From 58720a43974da688021531ed107dc8693b62ca39 Mon Sep 17 00:00:00 2001 From: Javier Sancho Date: Fri, 30 Oct 2020 19:53:25 +0100 Subject: [PATCH] Check if table exists before getting table definition --- datasette_connectors/cursor.py | 3 ++- tests/test_api.py | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/datasette_connectors/cursor.py b/datasette_connectors/cursor.py index f3898cc..bf3a1b1 100644 --- a/datasette_connectors/cursor.py +++ b/datasette_connectors/cursor.py @@ -67,7 +67,8 @@ class Cursor: if self.connector.table_exists(params[0]): results = [{'1': '1'}] elif sql == "select sql from sqlite_master where name = :n and type=:t": - results = [{'sql': self.connector.table_definition(params['t'], params['n'])}] + if self.connector.table_exists(params['n']): + results = [{'sql': self.connector.table_definition(params['t'], params['n'])}] elif sql == "select sql from sqlite_master where tbl_name = :n and type='index' and sql is not null": results = [{'sql': sql} for sql in self.connector.indices_definition(params['n'])] else: diff --git a/tests/test_api.py b/tests/test_api.py index 25bd297..e7303a8 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -64,9 +64,9 @@ def test_table_json(app_client): def test_table_not_exists_json(app_client): assert { 'ok': False, - 'title': 'Invalid SQL', - 'error': 'no such table: blah', - 'status': 400, + 'error': 'Table not found: blah', + 'status': 404, + 'title': None, } == app_client.get('/dummy_tables/blah.json').json def test_table_shape_arrays(app_client): -- 2.39.2