Don't link a foreign key that points at a table that does not exist

Closes #1515
This commit is contained in:
Dipak Chaudhari 2026-09-25 00:12:23 +05:30 • committed by GitHub
commit 83cef452ea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 36 additions and 0 deletions

View file

@ -2317,6 +2317,10 @@ ORDER BY allowed.parent, allowed.child
from datasette.resources import TableResource
other_table = fk["other_table"]
if not await db.table_exists(other_table):
# SQLite accepts a foreign key to a table that does not exist, and
# linking to it would only lead to a 404
return {}
other_column = fk["other_column"]
if other_column is None:
other_pks = await db.primary_keys(other_table)