Skip to content

Refs #37348 -- Added tests for removing null from GeneratedField. - #21979

Closed
nessita wants to merge 1 commit into
django:mainfrom
nessita:ticket-37348
Closed

nessita wants to merge 1 commit into
django:mainfrom
nessita:ticket-37348

Conversation

@nessita

@nessita nessita commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

🛑 WIP -- need to test all DB backends

Trac ticket number

ticket-37348

Branch description

The fields.W225 check warns that null has no effect on GeneratedField, but acting on that advice changes behavior: negated lookups stop matching rows where the generated value is NULL, and the resulting migration tries to make the column NOT NULL.

These tests show how each DB backend handles both problems, to help decide reverting the check and making GeneratedField always nullable.

AI Assistance Disclosure (REQUIRED)

  • No AI tools were used in preparing this PR.
  • [X If AI tools were used, I have disclosed which ones, and fully reviewed and verified their output.

Claude code Opus 5 was used to research on the varied support from the DB backends Django supports.

Checklist

  • This PR follows the contribution guidelines.
  • This PR does not disclose a security vulnerability (see vulnerability reporting).
  • This PR targets the main branch.
  • The commit message is written in past tense, mentions the ticket number (if applicable), and ends with a period (see guidelines).
  • I have not requested, and will not request, an automated AI review for this PR.

The fields.W225 check warns that null has no effect on GeneratedField,
but acting on that advice changes behavior: negated lookups stop
matching rows where the generated value is NULL, and the resulting
migration tries to make the column NOT NULL.

These tests show how each DB backend handles both problems, to help
decide reverting the check and making GeneratedField always nullable.
@nessita

nessita commented Sep 16, 2026

Copy link
Copy Markdown
Contributor Author

buildbot, test on oracle.

@nessita

nessita commented Sep 16, 2026

Copy link
Copy Markdown
Contributor Author

Closing after confirming that:

  • exclude() on a generated field without null=True drops rows where the generated value is NULL: fails on SQLite, PostgreSQL, MySQL, and MariaDB.
  • Altering a generated field from null=True to not null behaves differently on every backend:

Results:

  • PostgreSQL: ALTER COLUMN ... SET NOT NULL, fails if NULLs exist
  • MySQL: MODIFY without the AS clause, read as converting to a regular column: stored fails on NULLs, virtual errors
  • MariaDB: Same as MySQL
  • SQLite: Table rebuild ignores null, no-op
  • Oracle: No-op: GeneratedField inherits empty_strings_allowed = True from Field regardless of output_field, so Oracle treats it as always nullable (virtual tested on 19; stored not run)

@nessita nessita closed this Sep 16, 2026
@nessita
nessita deleted the ticket-37348 branch September 16, 2026 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant