From bd4dbc8519c24c2799dfa5e69bb3dc37a3f3092e Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Mon, 27 May 2019 17:16:36 -0700 Subject: [PATCH] Rename InterruptedError => QueryInterrupted, closes #490 --- datasette/app.py | 6 +++--- datasette/database.py | 6 +++--- datasette/facets.py | 16 ++++++++-------- datasette/utils.py | 2 +- datasette/views/base.py | 4 ++-- datasette/views/table.py | 4 ++-- docs/plugins.rst | 2 +- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/datasette/app.py b/datasette/app.py index 93527850..2ef7da41 100644 --- a/datasette/app.py +++ b/datasette/app.py @@ -26,7 +26,7 @@ from .renderer import json_renderer from .database import Database from .utils import ( - InterruptedError, + QueryInterrupted, Results, escape_css_string, escape_sqlite, @@ -346,7 +346,7 @@ class Datasette: ) try: results = await self.execute(database, sql, list(set(values))) - except InterruptedError: + except QueryInterrupted: pass else: for id, value in results: @@ -504,7 +504,7 @@ class Datasette: truncated = False except sqlite3.OperationalError as e: if e.args == ("interrupted",): - raise InterruptedError(e, sql, params) + raise QueryInterrupted(e, sql, params) if log_sql_errors: print( "ERROR: conn={}, sql = {}, params = {}: {}".format( diff --git a/datasette/database.py b/datasette/database.py index 5fac4925..e4915770 100644 --- a/datasette/database.py +++ b/datasette/database.py @@ -1,7 +1,7 @@ from pathlib import Path from .utils import ( - InterruptedError, + QueryInterrupted, detect_fts, detect_primary_keys, detect_spatialite, @@ -58,8 +58,8 @@ class Database: ).rows[0][0] counts[table] = table_count # In some cases I saw "SQL Logic Error" here in addition to - # InterruptedError - so we catch that too: - except (InterruptedError, sqlite3.OperationalError): + # QueryInterrupted - so we catch that too: + except (QueryInterrupted, sqlite3.OperationalError): counts[table] = None if not self.is_mutable: self.cached_table_counts = counts diff --git a/datasette/facets.py b/datasette/facets.py index c37bb650..76d73e51 100644 --- a/datasette/facets.py +++ b/datasette/facets.py @@ -7,7 +7,7 @@ from datasette.utils import ( path_with_added_args, path_with_removed_args, detect_json1, - InterruptedError, + QueryInterrupted, InvalidSql, sqlite3, ) @@ -175,7 +175,7 @@ class ColumnFacet(Facet): ), } ) - except InterruptedError: + except QueryInterrupted: continue return suggested_facets @@ -248,7 +248,7 @@ class ColumnFacet(Facet): "selected": selected, } ) - except InterruptedError: + except QueryInterrupted: facets_timed_out.append(column) return facet_results, facets_timed_out @@ -294,7 +294,7 @@ class ArrayFacet(Facet): ), } ) - except (InterruptedError, sqlite3.OperationalError): + except (QueryInterrupted, sqlite3.OperationalError): continue return suggested_facets @@ -359,7 +359,7 @@ class ArrayFacet(Facet): "selected": selected, } ) - except InterruptedError: + except QueryInterrupted: facets_timed_out.append(column) return facet_results, facets_timed_out @@ -406,7 +406,7 @@ class DateFacet(Facet): ), } ) - except (InterruptedError, sqlite3.OperationalError): + except (QueryInterrupted, sqlite3.OperationalError): continue return suggested_facets @@ -472,7 +472,7 @@ class DateFacet(Facet): "selected": selected, } ) - except InterruptedError: + except QueryInterrupted: facets_timed_out.append(column) return facet_results, facets_timed_out @@ -659,7 +659,7 @@ class ManyToManyFacet(Facet): "selected": selected, } ) - except InterruptedError: + except QueryInterrupted: facets_timed_out.append(destination_table) return facet_results, facets_timed_out diff --git a/datasette/utils.py b/datasette/utils.py index 2031126b..56fe2996 100644 --- a/datasette/utils.py +++ b/datasette/utils.py @@ -46,7 +46,7 @@ ENV SQLITE_EXTENSIONS /usr/lib/x86_64-linux-gnu/mod_spatialite.so """ -class InterruptedError(Exception): +class QueryInterrupted(Exception): pass diff --git a/datasette/views/base.py b/datasette/views/base.py index 4294784d..b8863ff3 100644 --- a/datasette/views/base.py +++ b/datasette/views/base.py @@ -14,7 +14,7 @@ from sanic.views import HTTPMethodView from datasette import __version__ from datasette.plugins import pm from datasette.utils import ( - InterruptedError, + QueryInterrupted, InvalidSql, LimitedWriter, format_bytes, @@ -368,7 +368,7 @@ class BaseView(RenderMixin): else: data, extra_template_data, templates = response_or_template_contexts - except InterruptedError: + except QueryInterrupted: raise DatasetteError( """ SQL query took too long. The time limit is controlled by the diff --git a/datasette/views/table.py b/datasette/views/table.py index e109856a..af5358dd 100644 --- a/datasette/views/table.py +++ b/datasette/views/table.py @@ -9,7 +9,7 @@ from sanic.request import RequestParameters from datasette.plugins import pm from datasette.utils import ( CustomRow, - InterruptedError, + QueryInterrupted, append_querystring, compound_keys_after_sql, escape_sqlite, @@ -527,7 +527,7 @@ class TableView(RowTableShared): await self.ds.execute(database, count_sql, from_sql_params) ) filtered_table_rows_count = count_rows[0][0] - except InterruptedError: + except QueryInterrupted: pass # facets support diff --git a/docs/plugins.rst b/docs/plugins.rst index 1b9250f0..bd32b3a6 100644 --- a/docs/plugins.rst +++ b/docs/plugins.rst @@ -652,7 +652,7 @@ Each Facet subclass implements a new type of facet operation. The class should l "results": facet_results_values, "truncated": len(facet_rows_results) > facet_size, } - except InterruptedError: + except QueryInterrupted: facets_timed_out.append(column) return facet_results, facets_timed_out