Skip to content

Keep already-nullable columns nullable when transforming NOT NULL constraints - #959

Closed
chinh13eboi2luae-ui wants to merge 1 commit into
simonw:mainfrom
chinh13eboi2luae-ui:oss-ai/simonw/sqlite-utils/944
Closed

chinh13eboi2luae-ui wants to merge 1 commit into
simonw:mainfrom
chinh13eboi2luae-ui:oss-ai/simonw/sqlite-utils/944

Conversation

@chinh13eboi2luae-ui

@chinh13eboi2luae-ui chinh13eboi2luae-ui commented Nov 21, 2026 •

Copy link
Copy Markdown

Table.transform(not_null={"age": False}) adds NOT NULL when age is already nullable. Existing NULL rows cause an IntegrityError, while other tables silently acquire a constraint.

Use set.discard() for an explicit False so removing an absent constraint is a no-op. The existing handling of true values and renamed columns continues through the same code path. A regression test verifies that an already-nullable column stays nullable.

Fixes #944.

Validation

Tests ran on Windows using a local Docker Linux container with Python 3.12, SpatiaLite and the repository's development dependencies. Container networking was disabled.

  • Base checkout 9c66bafa52ae completed with 1512 passed, 1 skipped, 33 warnings in 8.93s.
  • Patched checkout completed with 1513 passed, 1 skipped, 33 warnings in 8.97s.
  • The new regression test fails against the unchanged base source and passes with the fix.
  • Independent API and CLI checks cover NULL rows, populated nullable columns, inserting NULL after transformation, and removing constraints while renaming columns.
  • Black, flake8 and mypy passed for the configured checks.
export PYTHONPATH=.; gcc tests/ext.c -fPIC -shared -o tests/ext.so && python -m pytest -q && black --check sqlite_utils/db.py tests/test_transform.py && flake8 sqlite_utils/db.py tests/test_transform.py && mypy --cache-dir=/tmp/mypy-cache sqlite_utils
Docker check output
1513 passed, 1 skipped, 33 warnings in 8.97s
2 files would be left unchanged.
Success: no issues found in 10 source files
Issue 944 API and CLI reproductions passed

AI assistance

The patch and regression test were generated through an LLM gateway, then reviewed with Codex and verified using the Docker checks above.

Verification request

Please confirm that the original reproduction and the --not-null-false age CLI option preserve existing NULL values and leave the column nullable.


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

GitHub Actions currently reports action_required for the test workflows. These workflows need maintainer approval to run for this contribution.

@chinh13eboi2luae-ui chinh13eboi2luae-ui changed the title Fix #944: transform(not_null={"col": False}) adds NOT NULL to a nullable column Keep already-nullable columns nullable when transforming NOT NULL constraints Nov 21, 2026
@chinh13eboi2luae-ui

Copy link
Copy Markdown
Author

@simonw Could you test this branch using the steps for #944 and confirm whether the fix works in your environment? The PR description has the verification details.

@simonw

simonw commented Nov 29, 2026

Copy link
Copy Markdown
Owner

@simonw simonw closed this 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.

transform(not_null={"col": False}) adds NOT NULL to a nullable column

2 participants