{"html_url": "https://github.com/simonw/datasette/issues/716#issuecomment-609106252", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/716", "id": 609106252, "node_id": "MDEyOklzc3VlQ29tbWVudDYwOTEwNjI1Mg==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-04-04T23:58:12Z", "updated_at": "2020-04-04T23:58:12Z", "author_association": "OWNER", "body": "I think I'll use `git bisect run` for this one, mainly to practice using it. https://git-scm.com/docs/git-bisect#_bisect_run", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 594168758, "label": "extra_template_vars() sending wrong view_name for index"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/716#issuecomment-609107679", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/716", "id": 609107679, "node_id": "MDEyOklzc3VlQ29tbWVudDYwOTEwNzY3OQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-04-05T00:10:37Z", "updated_at": "2020-04-05T00:11:06Z", "author_association": "OWNER", "body": "Once I fix this bug I should update https://github.com/simonw/museums to deploy using the latest Datasette release as opposed to being anchored to 286ed28.\r\n\r\nhttps://github.com/simonw/museums/blob/1bbed542617757e9e276a5098193d6288b7f421d/.github/workflows/push.yml#L61", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 594168758, "label": "extra_template_vars() sending wrong view_name for index"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/716#issuecomment-609109354", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/716", "id": 609109354, "node_id": "MDEyOklzc3VlQ29tbWVudDYwOTEwOTM1NA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-04-05T00:30:30Z", "updated_at": "2020-04-05T00:31:55Z", "author_association": "OWNER", "body": "In order to use `git bisect run` I need to write a standalone script that can tell if the bug is present or not.\r\n\r\nI'm going to use something I can execute with `pytest`, inspired loosely by this code:\r\n\r\nhttps://github.com/simonw/datasette/blob/7656fd64d8b6a32ebc34d89c1b8711cc5ea240f7/tests/test_plugins.py#L205-L227", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 594168758, "label": "extra_template_vars() sending wrong view_name for index"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/716#issuecomment-609453886", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/716", "id": 609453886, "node_id": "MDEyOklzc3VlQ29tbWVudDYwOTQ1Mzg4Ng==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-04-05T17:38:38Z", "updated_at": "2020-04-05T17:42:14Z", "author_association": "OWNER", "body": "OK, here's the test harness. Three files:\r\n\r\n`check_view_name.py`\r\n```python\r\nimport asyncio\r\nimport pathlib\r\nfrom datasette.app import Datasette\r\nimport httpx\r\n\r\nroot = pathlib.Path(__file__).parent\r\n\r\n\r\nasync def run_check():\r\n ds = Datasette(\r\n [], template_dir=str(root / \"templates\"), plugins_dir=str(root / \"plugins\")\r\n )\r\n async with httpx.AsyncClient(app=ds.app()) as client:\r\n response = await client.get(\"http://localhost/\")\r\n assert 200 == response.status_code\r\n assert b\"view_name:index\" == response.content, response.content\r\n\r\n\r\nif __name__ == \"__main__\":\r\n loop = asyncio.get_event_loop()\r\n loop.run_until_complete(run_check())\r\n```\r\n\r\n`templates/index.html`\r\n```\r\nview_name:{{ view_name }}\r\n```\r\n`plugins/extra_vars.py`\r\n```python\r\nfrom datasette import hookimpl\r\n\r\n\r\n@hookimpl\r\ndef extra_template_vars(view_name):\r\n return {\"view_name\": view_name}\r\n```", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 594168758, "label": "extra_template_vars() sending wrong view_name for index"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/716#issuecomment-609454072", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/716", "id": 609454072, "node_id": "MDEyOklzc3VlQ29tbWVudDYwOTQ1NDA3Mg==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-04-05T17:39:47Z", "updated_at": "2020-04-05T17:39:47Z", "author_association": "OWNER", "body": "`python check_view_name.py` against 286ed28 exits cleanly.\r\n\r\n`python check_view_name.py` against current master (e0e7a0fa) fails:\r\n\r\n```\r\n$ python check_view_name.py \r\nTraceback (most recent call last):\r\n File \"check_view_name.py\", line 16, in \r\n loop.run_until_complete(run_check())\r\n File \"/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/base_events.py\", line 579, in run_until_complete\r\n return future.result()\r\n File \"check_view_name.py\", line 11, in run_check\r\n assert b\"view_name:index\" == response.content, response.content\r\nAssertionError: b'view_name:None'\r\n```\r\n\r\n", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 594168758, "label": "extra_template_vars() sending wrong view_name for index"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/716#issuecomment-609456030", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/716", "id": 609456030, "node_id": "MDEyOklzc3VlQ29tbWVudDYwOTQ1NjAzMA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-04-05T17:52:39Z", "updated_at": "2020-04-05T20:02:13Z", "author_association": "OWNER", "body": "Found it. Prior to that change I passed `view_name` to the callbacks like this:\r\n\r\nhttps://github.com/simonw/datasette/blob/286ed286b68793532c2a38436a08343b45cfbc91/datasette/views/base.py#L114-L132\r\n\r\nI switched over to doing this:\r\n\r\nhttps://github.com/simonw/datasette/blob/07e208cc6d9e901b87552c1be2854c220b3f9b6d/datasette/views/base.py#L95-L97\r\n\r\nBut forgot to pass in the optional `view_name=` argument to that `render_template()` method:\r\n\r\nhttps://github.com/simonw/datasette/blob/2aaad72789c427875426673c1a43e67c86fc970e/datasette/app.py#L554-L556\r\n\r\nNext step: write a failing test, then fix it.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 594168758, "label": "extra_template_vars() sending wrong view_name for index"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/716#issuecomment-609461331", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/716", "id": 609461331, "node_id": "MDEyOklzc3VlQ29tbWVudDYwOTQ2MTMzMQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-04-05T18:31:32Z", "updated_at": "2020-04-05T20:04:08Z", "author_association": "OWNER", "body": "The test ended up being a bit fiddly - here it is:\r\n\r\nhttps://github.com/simonw/datasette/blob/09253817dea3c131553494f9b2eb9c03f94ae761/tests/test_plugins.py#L266-L317\r\n\r\nI used `tmp_path_factory` here because the `tmpdir` fixture I usually use isn't compatible with `scope=\"session\"`, and I wanted to only create those temporary plugins and templates directories once rather than create them for each run of the parametrized test function.\r\n\r\nIn writing this I realized that the `name` on the `QueryView` class wasn't being used, because that class is currently just used for its `.data()` method:\r\n\r\nhttps://github.com/simonw/datasette/blob/09253817dea3c131553494f9b2eb9c03f94ae761/datasette/views/database.py#L27-L31\r\n\r\nhttps://github.com/simonw/datasette/blob/07e208cc6d9e901b87552c1be2854c220b3f9b6d/datasette/views/table.py#L224-L227\r\n\r\nSo I removed the `name = \"query\"` line since it was misleading.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 594168758, "label": "extra_template_vars() sending wrong view_name for index"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/716#issuecomment-609455243", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/716", "id": 609455243, "node_id": "MDEyOklzc3VlQ29tbWVudDYwOTQ1NTI0Mw==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-04-05T17:47:33Z", "updated_at": "2020-04-05T17:47:33Z", "author_association": "OWNER", "body": "You start `git bisect` by giving it a known bad commit and a known good one:\r\n```\r\ngit bisect start master 286ed28 \r\n```\r\nThen you tell it to start running your script:\r\n```\r\ngit bisect run python ../datasette-issue-716/check_view_name.py\r\n```\r\nHere's what I got:\r\n```\r\n(datasette) ~/Dropbox/Development/datasette $ git bisect start master 286ed28\r\nBisecting: 30 revisions left to test after this (roughly 5 steps)\r\n[dc80e779a2e708b2685fc641df99e6aae9ad6f97] Handle scope path if it is a string\r\n(datasette) ~/Dropbox/Development/datasette $ git bisect run python ../datasette-issue-716/check_view_name.py\r\nrunning python ../datasette-issue-716/check_view_name.py\r\nTraceback (most recent call last):\r\n...\r\nBisecting: 15 revisions left to test after this (roughly 4 steps)\r\n[7c6a9c35299f251f9abfb03fd8e85143e4361709] Better tests for prepare_connection() plugin hook, refs #678\r\nrunning python ../datasette-issue-716/check_view_name.py\r\nTraceback (most recent call last):\r\n...\r\nBisecting: 7 revisions left to test after this (roughly 3 steps)\r\n[0091dfe3e5a3db94af8881038d3f1b8312bb857d] More reliable tie-break ordering for facet results\r\nrunning python ../datasette-issue-716/check_view_name.py\r\nTraceback (most recent call last):\r\n...\r\nBisecting: 3 revisions left to test after this (roughly 2 steps)\r\n[ce12244037b60ba0202c814871218c1dab38d729] Release notes for 0.35\r\nrunning python ../datasette-issue-716/check_view_name.py\r\nTraceback (most recent call last):\r\n...\r\nBisecting: 0 revisions left to test after this (roughly 1 step)\r\n[4d7dae9eb75e5430c3ee3c369bb5cd9ba0a148bc] Added a bunch more plugins to the Ecosystem page\r\nrunning python ../datasette-issue-716/check_view_name.py\r\nTraceback (most recent call last):\r\n...\r\n70b915fb4bc214f9d064179f87671f8a378aa127 is the first bad commit\r\ncommit 70b915fb4bc214f9d064179f87671f8a378aa127\r\nAuthor: Simon Willison \r\nDate: Tue Feb 4 12:26:17 2020 -0800\r\n\r\n Datasette.render_template() method, closes #577\r\n \r\n Pull request #664.\r\n\r\n:040000 040000 def9e31252e056845609de36c66d4320dd0c47f8 da19b7f8c26d50a4c05e5a7f05220b968429725c M\tdatasette\r\nbisect run success\r\n```\r\nSo 70b915fb4bc214f9d064179f87671f8a378aa127 introduced the bug!", "reactions": "{\"total_count\": 1, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 1, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 594168758, "label": "extra_template_vars() sending wrong view_name for index"}, "performed_via_github_app": null}