﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
35910	Use violation_error_message on UniqueContraint when only fields and no constraint is provided	James Walters		"I have a model with the following UniqueConstraint:

{{{
models.UniqueConstraint(
  fields=[""client"", ""location"", ""description"", ""affects_all_locations""],
  name=""unique_desc_per_location_per_client"",
  violation_error_message=""A closure with this description already exists for this location (or all locations)."",
)
}}}

Instead of seeing the error message I provided, I get ""Closure with this Client, Location, Description and Affects all locations already exists."" Upon consulting the [https://docs.djangoproject.com/en/5.1/ref/models/constraints/#id3 documentation], I see that this is actually the intended behavior: 

     This message is not used for UniqueConstraints with fields and without a condition. Such UniqueConstraints show the same message as constraints defined 
     with Field.unique or in Meta.unique_together.

The default error message, however, gives the names of model fields that users know nothing about, and the message I'm trying to provide gives the user a better explanation about what's going on. Currently, I would have to override the form's own validation to show this error message. However, I don't think this should be necessary, given that I can provide a violation_error_message straight to the UniqueConstraint.

I'm filing this under models/ORM since this is specifically related to model validation, though reclassify it as Forms if that turns out to be more appropriate.

If we decide we want to go in this direction, I'm open to working on a patch, but I'll wait to see if we agree that this behavior should be changed."	New feature	closed	Database layer (models, ORM)		Normal	duplicate	forms, models, unique constraints		Unreviewed	0	0	0	0	0	0
