Opened 4 years ago

Closed 2 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

Description

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)
            else:
                error_dict = self.message_dict
        else:
            if error_dict:
                error_dict[NON_FIELD_ERRORS] = self.messages
            else:
                error_dict = { NON_FIELD_ERRORS: self.messages, }
        return error_dict

Change History (5)

comment:1 Changed 4 years ago by russellm

  • Has patch set
  • Needs documentation unset
  • Needs tests set
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 4 years ago by lrekucki

  • Severity set to Normal
  • Type set to Bug

comment:3 Changed 3 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:4 Changed 3 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:5 Changed 2 years ago by bmispelon

  • Cc bmispelon@… added
  • Resolution set to invalid
  • Status changed from new to closed

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