Re: UniqueConstraint validation error message conditional vs non-conditional

2022-09-13 Thread charettes
Hello David, The proposed patch and test adjustments make sense to me, please open an associated ticket and PR. Thanks for digging this through and working on a solution! I think that an argument could be made for the `if e.code == "unique" and len(constraint.fields) == 1` branch in

Re: UniqueConstraint validation error message conditional vs non-conditional

2022-09-13 Thread Amol Rashinkar
Then what I do..? On Mon, 12 Sep, 2022, 8:36 pm David Sanders, wrote: > Hi Simon, > > > This should already work for constraints over a single field but not on > the ones with multiple fields[0] which is covered by the suite[1] but it > doesn't look like UniqueConstraint.validate is providing

Re: UniqueConstraint validation error message conditional vs non-conditional

2022-09-12 Thread David Sanders
Hi Simon, > This should already work for constraints over a single field but not on the ones with multiple fields[0] which is covered by the suite[1] but it doesn't look like UniqueConstraint.validate is providing code="unique" which might be the source of the issue you are encountering? Yep

Re: UniqueConstraint validation error message conditional vs non-conditional

2022-09-12 Thread charettes
Hello David > Would it be possible to group the message by field in the same way as standard unique? This should already work for constraints over a single field but not on the ones with multiple fields[0] which is covered by the suite[1] but it doesn't look like UniqueConstraint.validate is

Re: UniqueConstraint validation error message conditional vs non-conditional

2022-09-11 Thread David Sanders
Hi Simon, Cheers for the explanation. I'm ok with the error message being the "constraint is violated" generic message as I agree with what you're saying. Would it be possible to group the message by field in the same way as standard unique? ie, would this be an idea?:

Re: UniqueConstraint validation error message conditional vs non-conditional

2022-09-11 Thread charettes
Hello David, This is expected because Django doesn't have a way to express the constraint in words to present to the user when a condition, which could be complex, is provided. When no conditions are defined the metadata is easy to interpret to form a sentence out of ("Foo with this field0,

Re: UniqueConstraint validation error message conditional vs non-conditional

2022-09-11 Thread Othniel Davidson
nice one there On Sun, Sep 11, 2022 at 3:36 PM David Sanders wrote: > Hi folks (and in particular Simon Charette), > > I had a bit of a gotcha moment when a custom unique constraint validation > message disappeared when I added a condition to it. I won't raise a ticket > for this because it