[Django] #37244: Interaction between postgres ArrayField model field and ModelForm results in incomplete validation error messages

0 views
Skip to first unread message

Django

unread,
Aug 2, 2026, 6:00:58 PM (8 hours ago) Aug 2
to django-...@googlegroups.com
#37244: Interaction between postgres ArrayField model field and ModelForm results
in incomplete validation error messages
-----------------------+--------------------------------------
Reporter: Chris | Type: Bug
Status: new | Component: Forms
Version: 5.2 | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------+--------------------------------------
The contrib.postgres model `ArrayField` uses the validator(s) of the base
(model) field of the `ArrayField` to validate the items in the array. It
catches the `ValidationError` exceptions, then prefixes them with its own
prefix ("Item <x> in the array did not validate:") and re-raises this
exception with the `"item_invalid"` code.

`BaseModelForm` collects these model validation errors in the
`_post_clean()` method, and passes them to `_update_errors()`. This last
method replaces the message of a validation error if the code of that
validation error also is in the form field's `error_messages` dict, before
adding it to the form errors.

The problem here is of course that the helpful message from the model
(i.e. "Item <x> in the array did not validate: <reason from base field
validator>") gets replaced by only the prefix: "Item <x> in the array did
not validate:", and this is what is then rendered as the error in the
form, with the entire reason for the validation failure no longer shown.

This is not usually a problem if the ''model'' field also has a
corresponding custom ''form'' field which has the same validators, because
these are run first and should catch the same problems before the model
validators are tried, and these are not subject to the same replace-
validation-message-from-model-with-the-one-from-the-form mechanics.
--
Ticket URL: <https://code.djangoproject.com/ticket/37244>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 2, 2026, 6:05:15 PM (8 hours ago) Aug 2
to django-...@googlegroups.com
#37244: Interaction between postgres ArrayField model field and ModelForm results
in incomplete validation error messages
------------------------+--------------------------------------
Reporter: Chris | Owner: (none)
Type: Bug | Status: new
Component: Forms | Version: 5.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------+--------------------------------------
Comment (by Yassin Bahri):

If this gets triaged and accepted can I work on it if possible?
Thanks
--
Ticket URL: <https://code.djangoproject.com/ticket/37244#comment:1>
Reply all
Reply to author
Forward
0 new messages