-
-
Notifications
You must be signed in to change notification settings - Fork 709
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Incorrect foreign key references on catalog_columns table #2466
Comments
There are a bunch of other incorrect foreign key references in here: datasette/datasette/utils/internal_db.py Lines 20 to 62 in cd9182a
I'm also going to add a test that checks the internal DB schema has no incorrect references like that. |
This test currently fails: diff --git a/tests/test_internal_db.py b/tests/test_internal_db.py
index b41cabb4..246d795e 100644
--- a/tests/test_internal_db.py
+++ b/tests/test_internal_db.py
@@ -1,4 +1,5 @@
import pytest
+import sqlite_utils
# ensure refresh_schemas() gets called before interacting with internal_db
@@ -59,3 +60,25 @@ async def test_internal_foreign_keys(ds_client):
"table_name",
"from",
}
+
+
+@pytest.mark.asyncio
+async def test_internal_foreign_key_references(ds_client):
+ internal_db = await ensure_internal(ds_client)
+
+ def inner(conn):
+ db = sqlite_utils.Database(conn)
+ table_names = db.table_names()
+ for table in db.tables:
+ for fk in table.foreign_keys:
+ other_table = fk.other_table
+ other_column = fk.other_column
+ message = 'Column "{}.{}" references other column "{}.{}" which does not exist'.format(
+ table.name, fk.column, other_table, other_column
+ )
+ assert other_table in table_names, message + " (bad table)"
+ assert other_column in db[other_table].columns_dict, (
+ message + " (bad column)"
+ )
+
+ await internal_db.execute_fn(inner) |
simonw
added a commit
that referenced
this issue
Feb 13, 2025
Wrote this bug up here: https://simonwillison.net/2025/Feb/13/url-addressable-python/ |
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
Spotted this while playing around with Datasette Lite and
?install=datasette-visible-internal-db
:https://lite.datasette.io/?install=datasette-visible-internal-db&ref=1.0a17#/_internal/catalog_columns?_facet=type&_facet=database_name&_facet=is_pk&is_pk=4
Those foreign key references should point to
catalog_databases
andcatalog_tables
.The text was updated successfully, but these errors were encountered: