Skip to content

Commit

Permalink
Show interrupted query in resizing textarea, closes #1876
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Nov 1, 2022
1 parent 00632de commit 93a0228
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
6 changes: 5 additions & 1 deletion datasette/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,11 @@ async def get(self, request):
<p>SQL query took too long. The time limit is controlled by the
<a href="https://docs.datasette.io/en/stable/settings.html#sql-time-limit-ms">sql_time_limit_ms</a>
configuration option.</p>
<pre>{}</pre>
<textarea style="width: 90%">{}</textarea>
<script>
let ta = document.querySelector("textarea");
ta.style.height = ta.scrollHeight + "px";
</script>
""".format(
escape(ex.sql)
)
Expand Down
6 changes: 5 additions & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,11 @@ def test_sql_time_limit(app_client_shorter_time_limit):
"<p>SQL query took too long. The time limit is controlled by the\n"
'<a href="https://docs.datasette.io/en/stable/settings.html#sql-time-limit-ms">sql_time_limit_ms</a>\n'
"configuration option.</p>\n"
"<pre>select sleep(0.5)</pre>"
'<textarea style="width: 90%">select sleep(0.5)</textarea>\n'
"<script>\n"
'let ta = document.querySelector("textarea");\n'
'ta.style.height = ta.scrollHeight + "px";\n'
"</script>"
),
"status": 400,
"title": "SQL Interrupted",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def test_sql_time_limit(app_client_shorter_time_limit):
"""
<a href="https://docs.datasette.io/en/stable/settings.html#sql-time-limit-ms">sql_time_limit_ms</a>
""".strip(),
"<pre>select sleep(0.5)</pre>",
'<textarea style="width: 90%">select sleep(0.5)</textarea>',
]
for expected_html_fragment in expected_html_fragments:
assert expected_html_fragment in response.text
Expand Down

0 comments on commit 93a0228

Please sign in to comment.