Skip to content

Allow unexpected values for ChoiceField/MultipleChoiceField representations. #2839

Closed
@shangxiao

Description

@shangxiao

When an invalid value is present in the database that isn't part of the list of choices (perhaps dealing with a legacy database) a KeyError will be raised in to_representation() of ChoiceField/MultipleChoiceField.

Personally I'd like to see the behaviour more in line with the Django ORM's choices behaviour where the invalid value is still readable, perhaps by simply returning it from to_representation()

In case this is disagreeable, I think the KeyError should be caught and a new exception raised with a more easily debuggable error message explaining which field has the invalid value.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions