Skip to content

transform(not_null={"col": False}) no longer adds NOT NULL to a nullable column - #969

Merged
simonw merged 3 commits into
mainfrom
transform-not-null-false
Nov 29, 2026
Merged

simonw merged 3 commits into
mainfrom
transform-not-null-false

Conversation

@simonw

@simonw simonw commented Nov 29, 2026 •

Copy link
Copy Markdown
Owner

table.transform(not_null={"col": False}) removes a NOT NULL constraint, as documented. But if the column was already nullable, it added NOT NULL instead.

Reproducing it

db.execute("create table t (id integer primary key, a text, b text not null)")
print(db["t"].transform_sql(not_null={"a": False})[0])

Before this change, on 4.2.1:

CREATE TABLE "t_new_..." (
   "id" INTEGER PRIMARY KEY,
   "a" TEXT NOT NULL,
   "b" TEXT NOT NULL
);

a should have stayed TEXT. If the column contains nulls the transform then fails; if it doesn't, the column silently gains a constraint.

Cause

In transform_sql():

if value is False and key in create_table_not_null:
    create_table_not_null.remove(key)
else:
    create_table_not_null.add(key)

A False value for a column that is not currently NOT NULL falls through to the else and is added.

Fix

A true value adds the column to the NOT NULL set and anything else discards it.

Tests

New test_transform_not_null_false_leaves_nullable_column_nullable, which fails without the fix. The full suite passes locally (1510 passed, 4 skipped), along with black, flake8, mypy and cog --check.

🤖 Generated with Claude Code


📚 Documentation preview 📚: https://sqlite-utils--969.org.readthedocs.build/en/969/

…ble column

Passing False for a column that was already nullable fell through to the
branch that adds the constraint. False now always leaves the column
nullable.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.75%. Comparing base (9c66baf) to head (5889867).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #969   +/-   ##
=======================================
  Coverage   94.75%   94.75%           
=======================================
  Files          10       10           
  Lines        4516     4516           
=======================================
  Hits         4279     4279           
  Misses        237      237           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

simonw and others added 2 commits November 29, 2026 08:48
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
GitHub no longer provides the macos-14 runner image, so those jobs were
cancelled with "configuration 'macos-14-arm64-us-default' is not supported".
macos-latest already covers Apple Silicon.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@simonw
simonw merged commit 704d4a3 into main Nov 29, 2026
80 checks passed
simonw added a commit that referenced this pull request Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant