diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a1cb09b53..3a0698bfb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,7 @@ jobs: matrix: python-version: ["3.10", "3.11", "3.12", "3.13", "3.14", "3.15"] numpy: [0, 1] - os: [ubuntu-latest, macos-latest, windows-latest, macos-14] + os: [ubuntu-latest, macos-latest, windows-latest] steps: - uses: actions/checkout@v7 - name: Set up Python ${{ matrix.python-version }} diff --git a/sqlite_utils/db.py b/sqlite_utils/db.py index c011d9bb0..22d9aa008 100644 --- a/sqlite_utils/db.py +++ b/sqlite_utils/db.py @@ -3047,10 +3047,10 @@ def fk_with_renamed_columns(fk: ForeignKey) -> ForeignKey: for key, value in not_null.items(): # Column may have been renamed key = rename.get(key) or key - if value is False and key in create_table_not_null: - create_table_not_null.remove(key) - else: + if value: create_table_not_null.add(key) + else: + create_table_not_null.discard(key) elif isinstance(not_null, set): create_table_not_null.update((rename.get(k) or k) for k in not_null) elif not not_null: @@ -4789,7 +4789,7 @@ def insert_all( raise ValueError( "When using list-based iteration, the first yielded value must be a list of column name strings" ) - column_names = cast(list[str], list(first_record)) + column_names = list(first_record) all_columns = column_names num_columns = len(column_names) # Get the actual first data record diff --git a/tests/test_transform.py b/tests/test_transform.py index 873871308..5c7a4d3ec 100644 --- a/tests/test_transform.py +++ b/tests/test_transform.py @@ -308,6 +308,22 @@ def test_transform_remove_a_not_null(fresh_db): ) +def test_transform_not_null_false_leaves_nullable_column_nullable(fresh_db): + # not_null={"col": False} on a column that was already nullable + # used to add NOT NULL to it + dogs = fresh_db["dogs"] + dogs.insert({"id": 1, "name": "Cleo", "age": None}, pk="id") + dogs.transform(not_null={"age": False}) + assert dogs.schema == ( + 'CREATE TABLE "dogs" (\n' + ' "id" INTEGER PRIMARY KEY,\n' + ' "name" TEXT,\n' + ' "age" TEXT\n' + ")" + ) + assert list(dogs.rows) == [{"id": 1, "name": "Cleo", "age": None}] + + @pytest.mark.parametrize("not_null", [{"age"}, {"age": True}]) def test_transform_add_not_null_with_rename(fresh_db, not_null): dogs = fresh_db.table("dogs")