Skip to content

Commit

Permalink
Show error message on bad query, closes #619
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Jun 2, 2021
1 parent 9552414 commit ea5b237
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions datasette/templates/query.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ <h1 style="padding-left: 10px; border-left: 10px solid #{{ database_color(databa

<form class="sql" action="{{ urls.database(database) }}{% if canned_query %}/{{ canned_query }}{% endif %}" method="{% if canned_write %}post{% else %}get{% endif %}">
<h3>Custom SQL query{% if display_rows %} returning {% if truncated %}more than {% endif %}{{ "{:,}".format(display_rows|length) }} row{% if display_rows|length == 1 %}{% else %}s{% endif %}{% endif %}{% if not query_error %} <span class="show-hide-sql">{% if hide_sql %}(<a href="{{ path_with_removed_args(request, {'_hide_sql': '1'}) }}">show</a>){% else %}(<a href="{{ path_with_added_args(request, {'_hide_sql': '1'}) }}">hide</a>){% endif %}</span>{% endif %}</h3>
{% if query_error %}
<p class="message-error">{{ query_error }}</p>
{% if error %}
<p class="message-error">{{ error }}</p>
{% endif %}
{% if not hide_sql %}
{% if editable and allow_execute_sql %}
Expand Down
10 changes: 10 additions & 0 deletions tests/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -1402,6 +1402,16 @@ def test_zero_results(app_client, path):
assert 1 == len(soup.select("p.zero-results"))


def test_query_error(app_client):
response = app_client.get("/fixtures?sql=select+*+from+notatable")
html = response.text
assert '<p class="message-error">no such table: notatable</p>' in html
assert (
'<textarea id="sql-editor" name="sql">select * from notatable</textarea>'
in html
)


def test_config_template_debug_on():
with make_app_client(config={"template_debug": True}) as client:
response = client.get("/fixtures/facetable?_context=1")
Expand Down

0 comments on commit ea5b237

Please sign in to comment.