-
-
Notifications
You must be signed in to change notification settings - Fork 687
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Datasette shouldn't crash running against a database with missing extensions #2388
Comments
This happens because of We could ignore these class of errors with: elif e.args[0].startswith("no such module: "):
pass But other parts of the codebase will still call We could audit all cases of this and just return |
I'm going to create a minimal |
Creating it with sqlite-utils install sqlite-utils-sqlite-vec
echo '{"point": "[1,2,3]"}' | sqlite-utils insert vec.db vectors -
sqlite-utils vec.db 'create virtual table vec_vectors using vec0(point float[3]);'
sqlite-utils vec.db 'insert into vec_vectors(rowid, point) select rowid, point from vectors' That's a 48KB file: ls -lah vec.db
Datasette cannot currently load it (without its own plugin or the datasette vec.db
This works: datasette vec.db --load-extension "$(python -c 'import sqlite_vec; print(sqlite_vec.loadable_path())')" |
This conflicts slightly with Datasette's existing design with respect to SpatiaLite: currently Datasette shows you a useful error if you try to load a SpatiaLite database without activating the extension: datasette tests/spatialite.db
|
One solution: turn this into a warning that gets dumped to the console but Datasette still starts up as usual. Could even expand that a bit, so it knows a few other extensions (like |
Relevant code: Lines 791 to 825 in 05dfd34
Which runs datasette/datasette/utils/__init__.py Lines 965 to 981 in 05dfd34
|
Design options:
The second option is nicer, but requires more design decisions: where should that message go? How should we explain it to users? So I think option 3 is the way to go for the moment. |
OK, this is actually a lot of work to implement. I tried this so far: diff --git a/datasette/utils/__init__.py b/datasette/utils/__init__.py
index 073d6e86..5469252b 100644
--- a/datasette/utils/__init__.py
+++ b/datasette/utils/__init__.py
@@ -19,6 +19,7 @@ import time
import types
import secrets
import shutil
+import sys
from typing import Iterable, List, Tuple
import urllib
import yaml
@@ -978,7 +979,8 @@ def check_connection(conn):
if e.args[0] == "no such module: VirtualSpatialIndex":
raise SpatialiteConnectionProblem(e)
else:
- raise ConnectionProblem(e)
+ print(str(e), file=sys.stderr)
+ # raise ConnectionProblem(e)
class BadMetadataError(Exception):
diff --git a/datasette/utils/internal_db.py b/datasette/utils/internal_db.py
index 626dd137..f5ae68b2 100644
--- a/datasette/utils/internal_db.py
+++ b/datasette/utils/internal_db.py
@@ -1,5 +1,6 @@
+import sys
import textwrap
-from datasette.utils import table_column_details
+from datasette.utils import table_column_details, sqlite3
async def init_internal_db(db):
@@ -137,7 +138,11 @@ async def populate_schema_tables(internal_db, db):
tables_to_insert.append(
(database_name, table_name, table["rootpage"], table["sql"])
)
- columns = table_column_details(conn, table_name)
+ try:
+ columns = table_column_details(conn, table_name)
+ except sqlite3.OperationalError as ex:
+ print(f"Error accessing table {table_name}: {str(ex)}", file=sys.stderr)
+ continue
columns_to_insert.extend(
{
**{"database_name": database_name, "table_name": table_name}, And it's revealing that there are MANY places in Datasette that might attempt to read the columns from one of these tables and run into an error. For example, running this above patch with
I don't think I can fix this for the 1.0a15 alpha: |
This would be a bit easier if I moved all code in Datasette that loops through a list of tables to consult the internal database catalog tables for those, then I could include these unreadable tables in that but have a "unreadable = 1" column which could be used to filter them out. |
E.g. after https://til.simonwillison.net/sqlite/sqlite-vec my https://til.simonwillison.net/tils.db needs the
vec0
extension if you are going to browse thevec_tils
table, but the rest of the UI should work by skipping that table when scanning tables.The text was updated successfully, but these errors were encountered: