You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
I'd like to add empty as choice on a nullable field, see: https://docs.djangoproject.com/en/5.1/ref/models/fields/#enumeration-types (at the bottom of the paragraph). However AssertionError: Invalid nullable case is then raised on scheme generation. I noticed this error is also raised when overriding the choices and adding a (None, 'unknown') tuple to the choices.
It took me some time to dive in deeper. It seems I'm not losing the enums, but they are - randomly - re-ordered when I use ENUM_ADD_EXPLICIT_BLANK_NULL_CHOICE=True.
Take for example:
ALL_STATES = frozenset({
PENDING, RECEIVED, STARTED, SUCCESS, FAILURE, RETRY, REVOKED,
})
ALL_STATES_INCLUDING_PROGRESS = [x for x in states.ALL_STATES] + [PROGRESS_STATE]
class SomeSerializer:
state = serializers.ChoiceField(required=False, choices=ALL_STATES_INCLUDING_PROGRESS)
With ENUM_ADD_EXPLICIT_BLANK_NULL_CHOICE=False it correctly renders to:
Uh oh!
There was an error while loading. Please reload this page.
Describe the bug
I'd like to add empty as choice on a nullable field, see: https://docs.djangoproject.com/en/5.1/ref/models/fields/#enumeration-types (at the bottom of the paragraph). However
AssertionError: Invalid nullable case
is then raised on scheme generation. I noticed this error is also raised when overriding the choices and adding a (None, 'unknown') tuple to the choices.To Reproduce
Add
OR
to the choices
Expected behavior
I would expect the field to have null as a choice.
I have tried all other methods to make the (read_only) field nullable, but this seems impossible.
What have I tried:
Add allow_null=True, allow_blank=True, required=False, amongst others.
I do have
"ENUM_ADD_EXPLICIT_BLANK_NULL_CHOICE": False,
because otherwise I loose a lot of Enums (they become simply "string", not enum, in the scheme generation).
I have also noticed that upgrading to 0.28.0 also made me lose a lot of read-only Enums, so I'm still on 0.27.2.
The text was updated successfully, but these errors were encountered: