From 50e817801f90d07468ea394ef562d55d8940d124 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Mon, 13 Nov 2017 16:44:08 -0800 Subject: [PATCH] Fixed #83 Turns out we had a redirect bug as well. --- datasette/app.py | 7 +++++-- tests/test_app.py | 11 +++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/datasette/app.py b/datasette/app.py index eb871c05..cb0f462a 100644 --- a/datasette/app.py +++ b/datasette/app.py @@ -99,6 +99,8 @@ class BaseView(HTTPMethodView): ) if 'table' in kwargs: should_redirect += '/' + kwargs['table'] + if 'pk_path' in kwargs: + should_redirect += '/' + kwargs['pk_path'] if 'as_json' in kwargs: should_redirect += kwargs['as_json'] if 'as_db' in kwargs: @@ -487,8 +489,9 @@ class RowView(BaseView): params = {} for i, pk_value in enumerate(pk_values): params['p{}'.format(i)] = pk_value - rows = await self.execute(name, sql, params) - columns = [r[0] for r in rows.description] + # rows, truncated, description = await self.execute(name, sql, params, truncate=True) + rows, truncated, description = await self.execute(name, sql, params, truncate=True) + columns = [r[0] for r in description] rows = list(rows) if not rows: raise NotFound('Record not found: {}'.format(pk_values)) diff --git a/tests/test_app.py b/tests/test_app.py index 39030c94..95a499a0 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -170,6 +170,17 @@ def test_view(app_client): }] +def test_row(app_client): + _, response = app_client.get('/test_tables/simple_primary_key/1', allow_redirects=False) + assert response.status == 302 + assert response.headers['Location'].endswith('/1') + _, response = app_client.get('/test_tables/simple_primary_key/1') + assert response.status == 200 + _, response = app_client.get('/test_tables/simple_primary_key/1.jsono') + assert response.status == 200 + assert [{'pk': '1', 'content': 'hello'}] == response.json['rows'] + + TABLES = ''' CREATE TABLE simple_primary_key ( pk varchar(30) primary key,