Opened 3 months ago

Last modified 3 months ago

#28507 assigned New feature

Allow ValidationErrors to equal each other when created identically

Reported by: kamni Owned by: caleb logan
Component: Core (Other) Version: 1.11
Severity: Normal Keywords: ValidationError
Cc: Markus Holtermann Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by kamni)

Currently ValidationErrors (django.core.exceptions.ValidationError) that have identical messages don't equal each other, which is counter-intuitive, and can make certain kinds of testing more complicated. Please add an __eq__ method that allows two ValidationErrors to be compared.

Ideally, this would be more than just a simple self.messages == other.messages. It would be most helpful if the comparison were independent of the order in which errors were raised in a field or in non_field_errors.

Change History (4)

comment:1 Changed 3 months ago by kamni

Description: modified (diff)

comment:2 Changed 3 months ago by Markus Holtermann

Triage Stage: UnreviewedAccepted

comment:3 Changed 3 months ago by Markus Holtermann

I probably wouldn't want to limit the comparison to an error's message but rather to its full set of attributes (message, code, params). While params is always pushed into message when iterating over the errors in an ValidationError, I believe it can be beneficial to know if the params that were put inside are the same.

comment:4 Changed 3 months ago by caleb logan

Owner: changed from nobody to caleb logan
Status: newassigned
Note: See TracTickets for help on using tickets.
Back to Top