Opened 7 years ago

Closed 5 years ago

#15166 closed Bug (invalid)

Code error in ValidationError.update_error_dict

Reported by: zvikico Owned by: nobody
Component: Core (Other) Version: 1.3-beta
Severity: Normal Keywords:
Cc: bmispelon@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no


There's a minor bug in ValidationError.update_error_dict. The code receives an error_dict which might be None (and perhaps it should have a default None value).
The code has two options, one when a message_dict exists and one that it doesn't.
If the message_dict exists, the code checks for a null error_dict and returns the message_dict instead.
If the message_dict does not exist, the code assumes the error_dict input is a dict without checking for None.

Here's a suggested alternative for the code:

    def update_error_dict(self, error_dict = None):
        if hasattr(self, 'message_dict'):
            if error_dict:
                for k, v in self.message_dict.items():
                    error_dict.setdefault(k, []).extend(v)
                error_dict = self.message_dict
            if error_dict:
                error_dict[NON_FIELD_ERRORS] = self.messages
                error_dict = { NON_FIELD_ERRORS: self.messages, }
        return error_dict

Change History (5)

comment:1 Changed 7 years ago by Russell Keith-Magee

Has patch: set
Needs tests: set
Triage Stage: UnreviewedAccepted

comment:2 Changed 7 years ago by Łukasz Rekucki

Severity: Normal
Type: Bug

comment:3 Changed 6 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:4 Changed 6 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:5 Changed 5 years ago by Baptiste Mispelon

Cc: bmispelon@… added
Resolution: invalid
Status: newclosed

Validation.update_error_dict is only used in Model.full_clean, where it always passes a dictionary (never None).

For this reason, I'm marking this as invalid.

Feel free to reopen this bug if you can provide a concrete example of how this affects you.

Note: See TracTickets for help on using tickets.
Back to Top