Opened 3 years ago

Closed 2 weeks ago

#28507 closed New feature (fixed)

Allow ValidationErrors to equal each other when created identically

Reported by: kamni Owned by: David Smith
Component: Core (Other) Version: master
Severity: Normal Keywords: ValidationError
Cc: Markus Holtermann Triage Stage: Ready for checkin
Has patch: yes 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 (9)

comment:1 Changed 3 years ago by kamni

Description: modified (diff)

comment:2 Changed 3 years ago by Markus Holtermann

Triage Stage: UnreviewedAccepted

comment:3 Changed 3 years 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 years ago by caleb logan

Owner: changed from nobody to caleb logan
Status: newassigned

comment:5 Changed 17 months ago by felixxm

Has patch: set
Patch needs improvement: set

comment:6 Changed 3 weeks ago by David Smith

Owner: changed from caleb logan to David Smith
Patch needs improvement: unset
Last edited 3 weeks ago by felixxm (previous) (diff)

comment:7 Changed 3 weeks ago by felixxm

Patch needs improvement: set

comment:8 Changed 3 weeks ago by felixxm

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin
Version: 1.11master

comment:9 Changed 2 weeks ago by Mariusz Felisiak <felisiak.mariusz@…>

Resolution: fixed
Status: assignedclosed

In 95da207:

Fixed #28507 -- Made ValidationError.eq() ignore messages and params ordering.

Co-authored-by: caleb logan <clogan202@…>

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