Update _defaults["strict"] when necessary

Refs https://github.com/simonw/sqlite-utils/pull/788#issuecomment-4948505824
This commit is contained in:
Simon Willison 2026-07-11 16:31:58 -07:00
commit 5b9898ed9b
2 changed files with 15 additions and 0 deletions

View file

@ -2591,6 +2591,8 @@ class Table(Queryable):
self.db.execute("PRAGMA defer_foreign_keys=OFF;")
if should_disable_foreign_keys:
self.db.execute("PRAGMA foreign_keys=1;")
if strict is not None:
self._defaults["strict"] = strict
return self
def transform_sql(

View file

@ -602,6 +602,19 @@ def test_transform_to_strict_with_invalid_data(fresh_db):
assert fresh_db.table_names() == ["dogs"]
def test_transform_strict_updates_default(fresh_db):
if not fresh_db.supports_strict:
pytest.skip("SQLite version does not support strict tables")
table = fresh_db.table("items", strict=True)
table.create({"id": int})
table.transform(strict=False)
assert table.strict is False
table.create({"id": int}, replace=True)
assert table.strict is False
@pytest.mark.parametrize(
"indexes, transform_params",
[