home / github

Menu
  • GraphQL API

github

Custom SQL query returning 8 rows (hide)

Query parameters

This data as json, CSV

html_urlissue_urlidnode_idusercreated_atupdated_atauthor_associationbodyreactionsissueperformed_via_github_app
https://github.com/simonw/datasette/issues/1651#issuecomment-1060853226 https://api.github.com/repos/simonw/datasette/issues/1651 1060853226 IC_kwDOBm6k_c4_O1Xq 9599 2022-03-07T16:04:26Z 2022-03-07T16:04:26Z OWNER Here's the relevant code: https://github.com/simonw/datasette/blob/1baa030eca375f839f3471237547ab403523e643/datasette/utils/__init__.py#L753-L772 https://github.com/simonw/datasette/blob/1baa030eca375f839f3471237547ab403523e643/datasette/views/base.py#L451-L479 {"total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0} 1161584460  
https://github.com/simonw/datasette/issues/1651#issuecomment-1061053094 https://api.github.com/repos/simonw/datasette/issues/1651 1061053094 IC_kwDOBm6k_c4_PmKm 9599 2022-03-07T19:29:01Z 2022-03-07T19:29:01Z OWNER I found an obscure bug in #1650 which I can fix with this too. The following test should pass: ```python @pytest.mark.parametrize( "path,expected", ( ( "/fivethirtyeight/twitter-ratio%2Fsenators", "/fivethirtyeight/twitter-2Dratio-2Fsenators", ), ( "/fixtures/table%2Fwith%2Fslashes.csv", "/fixtures/table-2Fwith-2Fslashes-2Ecsv", ), # query string should be preserved ("/foo/bar%2Fbaz?id=5", "/foo/bar-2Fbaz?id=5"), ), ) def test_redirect_percent_encoding_to_dash_encoding(app_client, path, expected): response = app_client.get(path) assert response.status == 302 assert response.headers["location"] == expected ``` It currently fails like this: ``` > assert response.headers["location"] == expected E AssertionError: assert '/fixtures/table-2Fwith-2Fslashes.csv?_nofacet=1&_nocount=1' == '/fixtures/table-2Fwith-2Fslashes-2Ecsv' E - /fixtures/table-2Fwith-2Fslashes-2Ecsv E + /fixtures/table-2Fwith-2Fslashes.csv?_nofacet=1&_nocount=1 ``` Because the logic in that `get_format()` function notices that the table exists, and then weird things happen here: https://github.com/simonw/datasette/blob/1baa030eca375f839f3471237547ab403523e643/datasette/views/base.py#L288-L303 {"total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0} 1161584460  
https://github.com/simonw/datasette/issues/1651#issuecomment-1061169528 https://api.github.com/repos/simonw/datasette/issues/1651 1061169528 IC_kwDOBm6k_c4_QCl4 9599 2022-03-07T21:47:01Z 2022-03-07T21:47:01Z OWNER Wow, this code is difficult to follow! Look at this bit inside the `get_format()` method: https://github.com/simonw/datasette/blob/bb499942c15c4e2cfa4b6afab8f8debe5948c009/datasette/views/base.py#L469-L478 That's modifying the arguments that were extracted from the path by the routing regular expressions to have `table` as ` dash-decoded value! So calling `.get_format()` has the side effect of decoding the table names for you. Nasty. {"total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0} 1161584460  
https://github.com/simonw/datasette/issues/1651#issuecomment-1061170897 https://api.github.com/repos/simonw/datasette/issues/1651 1061170897 IC_kwDOBm6k_c4_QC7R 9599 2022-03-07T21:48:35Z 2022-03-07T21:48:35Z OWNER My attempts to simplify `get_format()` keep resulting in errors like this one: ``` File "/Users/simon/Dropbox/Development/datasette/datasette/views/base.py", line 474, in view_get response_or_template_contexts = await self.data( TypeError: TableView.data() missing 1 required positional argument: 'table' ``` I really need to clean this up. {"total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0} 1161584460  
https://github.com/simonw/datasette/issues/1651#issuecomment-1061223822 https://api.github.com/repos/simonw/datasette/issues/1651 1061223822 IC_kwDOBm6k_c4_QP2O 9599 2022-03-07T22:54:54Z 2022-03-07T22:54:54Z OWNER I'm going to do a review of how URL routing works at the moment for the various views. I edited down [the full list](https://github.com/simonw/datasette/blob/c5791156d92615f25696ba93dae5bb2dcc192c98/datasette/app.py#L997-L1107) a bit - these are the most relevant: ```python add_route(IndexView.as_view(self), r"/(?P<as_format>(\.jsono?)?$)") add_route( DatabaseView.as_view(self), r"/(?P<db_name>[^/]+?)(?P<as_format>" + renderer_regex + r"|.jsono|\.csv)?$", ) add_route( TableView.as_view(self), r"/(?P<db_name>[^/]+)/(?P<table_and_format>[^/]+?$)", ) add_route( RowView.as_view(self), r"/(?P<db_name>[^/]+)/(?P<table>[^/]+?)/(?P<pk_path>[^/]+?)(?P<as_format>" + renderer_regex + r")?$", ) ``` {"total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0} 1161584460  
https://github.com/simonw/datasette/issues/1651#issuecomment-1061359915 https://api.github.com/repos/simonw/datasette/issues/1651 1061359915 IC_kwDOBm6k_c4_QxEr 9599 2022-03-08T03:08:14Z 2022-03-08T03:09:24Z OWNER A lot of the code complexity here is caused by `DataView` ([here](https://github.com/simonw/datasette/blob/c5791156d92615f25696ba93dae5bb2dcc192c98/datasette/views/base.py#L182-L669)), which has the logic for CSV streaming and plugin formats such that it can be shared between tables and custom queries. It would be good to get rid of that subclassed shared code, figure out how to do it via a utility function instead. {"total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0} 1161584460  
https://github.com/simonw/datasette/issues/1651#issuecomment-1067382442 https://api.github.com/repos/simonw/datasette/issues/1651 1067382442 IC_kwDOBm6k_c4_nvaq 9599 2022-03-14T22:59:10Z 2022-03-14T22:59:10Z OWNER This work is now blocked on: - https://github.com/simonw/datasette/issues/1657 {"total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0} 1161584460  
https://github.com/simonw/datasette/issues/1651#issuecomment-1068319530 https://api.github.com/repos/simonw/datasette/issues/1651 1068319530 IC_kwDOBm6k_c4_rUMq 9599 2022-03-15T18:25:42Z 2022-03-15T18:25:42Z OWNER Done: - https://latest.datasette.io/fixtures/table~2Fwith~2Fslashes~2Ecsv - https://latest.datasette.io/fixtures/table~2Fwith~2Fslashes~2Ecsv.csv - https://latest.datasette.io/fixtures/table~2Fwith~2Fslashes~2Ecsv.json {"total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0} 1161584460  
Powered by Datasette · Queries took 1.471ms · About: simonw/datasette-graphql