Auto-set allow_none when an Enum member has value None#2992
Open
youdie006 wants to merge 1 commit into
Open
Conversation
Mirror fields.Constant(None): fields.Enum now defaults allow_none to True when the passed Enum contains a None-valued member, while preserving an explicit allow_none=False (which then errors on None load).
deckar01
reviewed
Jul 6, 2026
Member
Any reason no AI disclosure was added to this PR? |
Author
|
Fair question, and apologies for the inconsistency. Yes — like the linked PR, this was drafted with Claude Code; I've added the same AI disclosure to the description here. The change is verified locally (the added |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2985.
fields.Enumnow defaultsallow_none=Truewhen the passed Enum has a member whose value isNone, mirroringfields.Constant(None)(as suggested on the issue). An explicitallow_none=Falseis preserved, so loadingNonethen raises aValidationError.Added
TestEnumAllowNonecovering by-name and by-value, the explicit-allow_none=Falseerror case, and regression guards (an enum without a None member staysallow_none=False; an explicitallow_none=Trueis honored).AI disclosure: this PR was drafted with Claude Code (AI-assisted). The change was verified locally — the added
TestEnumAllowNonecases fail without the fix and pass with it, and the full test suite (1186 tests) passes.