{"html_url": "https://github.com/simonw/datasette/issues/1773#issuecomment-1196165351", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1773", "id": 1196165351, "node_id": "IC_kwDOBm6k_c5HTAjn", "user": {"value": 9599, "label": "simonw"}, "created_at": "2022-07-27T01:24:13Z", "updated_at": "2022-07-27T01:24:13Z", "author_association": "OWNER", "body": "Traceback:\r\n```\r\nTraceback (most recent call last):\r\n File \"/Users/simon/Dropbox/Development/datasette/datasette/app.py\", line 1264, in route_path\r\n response = await view(request, send)\r\n File \"/Users/simon/Dropbox/Development/datasette/datasette/views/base.py\", line 134, in view\r\n return await self.dispatch_request(request)\r\n File \"/Users/simon/Dropbox/Development/datasette/datasette/views/base.py\", line 91, in dispatch_request\r\n return await handler(request)\r\n File \"/Users/simon/Dropbox/Development/datasette/datasette/views/base.py\", line 361, in get\r\n response_or_template_contexts = await self.data(request, **data_kwargs)\r\n File \"/Users/simon/Dropbox/Development/datasette/datasette/views/table.py\", line 157, in data\r\n return await self._data_traced(request, default_labels, _next, _size)\r\n File \"/Users/simon/Dropbox/Development/datasette/datasette/views/table.py\", line 633, in _data_traced\r\n prefix = rows[-2][sort or sort_desc]\r\nIndexError: No item with that key\r\n```\r\nThat's this code here: https://github.com/simonw/datasette/blob/7af67b54b7d9bca43e948510fc62f6db2b748fa8/datasette/views/table.py#L631-L645", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1318907685, "label": "500 error if sorted by a column not in the ?_col= list"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/1773#issuecomment-1196166269", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1773", "id": 1196166269, "node_id": "IC_kwDOBm6k_c5HTAx9", "user": {"value": 9599, "label": "simonw"}, "created_at": "2022-07-27T01:26:09Z", "updated_at": "2022-07-27T01:26:09Z", "author_association": "OWNER", "body": "So the problem here is that in generating the `?_next=` next page link we need the value from the specified sort column - but we're not selecting it any more.\r\n\r\nPossible fixes:\r\n\r\n- Always include the sort column in the list of columns that are selected, then filter that out before they are displayed\r\n- Use a second query to figure out the `_sort` or `_sort_desc` value for that last row, since we know its primary key (we always select primary keys)\r\n\r\nNot sure which solution is more elegant. I think it might be the second one.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1318907685, "label": "500 error if sorted by a column not in the ?_col= list"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/1773#issuecomment-1196167102", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1773", "id": 1196167102, "node_id": "IC_kwDOBm6k_c5HTA--", "user": {"value": 9599, "label": "simonw"}, "created_at": "2022-07-27T01:28:02Z", "updated_at": "2022-07-27T01:28:02Z", "author_association": "OWNER", "body": "So code would look something like this:\r\n\r\n```python\r\ntry:\r\n prefix = rows[-2][sort or sort_desc]\r\nexcept KeyError:\r\n # Didn't select sort/sort_desc column - look up value by primary key instead\r\n primary_key = rows[-2][\"pk\"] # But more complex than this\r\n prefix = (await db.execute(\"select * from {table} where pk = ?\", [primary_key])).first_value()\r\n```", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1318907685, "label": "500 error if sorted by a column not in the ?_col= list"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/1773#issuecomment-1214407104", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1773", "id": 1214407104, "node_id": "IC_kwDOBm6k_c5IYmHA", "user": {"value": 9599, "label": "simonw"}, "created_at": "2022-08-14T16:06:25Z", "updated_at": "2022-08-14T16:06:25Z", "author_association": "OWNER", "body": "https://latest.datasette.io/fixtures/sortable?_sort_desc=sortable&_col=sortable_with_nulls works now.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1318907685, "label": "500 error if sorted by a column not in the ?_col= list"}, "performed_via_github_app": null}