[Django] #35532: Allow customizing errors processing in BaseModelFormSet.validate_unique()

16 views
Skip to first unread message

Django

unread,
Jun 18, 2024, 10:33:40 AM6/18/24
to django-...@googlegroups.com
#35532: Allow customizing errors processing in BaseModelFormSet.validate_unique()
--------------------------------------------+------------------------
Reporter: Christophe Henry | Owner: nobody
Type: New feature | Status: new
Component: Forms | Version: 5.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------------------------+------------------------
`BaseModelFormSet.validate_unique()`
[https://github.com/django/django/blob/main/django/forms/models.py#L850-L853
doesn't offer a way to customize errors] for instance to provide a more
specific message or add the error message to a specific field.

I propose to fix this problem by adding two `process_unique_error` and
`process_date_error` that get the form, fields and values as parameters.

Please check the enclosed patch for proposed solution.
--
Ticket URL: <https://code.djangoproject.com/ticket/35532>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 18, 2024, 10:33:45 AM6/18/24
to django-...@googlegroups.com
#35532: Allow customizing errors processing in BaseModelFormSet.validate_unique()
----------------------------------+--------------------------------------
Reporter: Christophe Henry | Owner: nobody
Type: New feature | Status: new
Component: Forms | Version: 5.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Changes (by Christophe Henry):

* Attachment "form.patch" added.

Django

unread,
Jun 19, 2024, 5:33:49 AM6/19/24
to django-...@googlegroups.com
#35532: Allow customizing errors processing in BaseModelFormSet.validate_unique()
----------------------------------+--------------------------------------
Reporter: Christophe Henry | Owner: nobody
Type: New feature | Status: closed
Component: Forms | Version: 5.0
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Changes (by Sarah Boyce):

* resolution: => wontfix
* status: new => closed

Comment:

Hi Christopheđź‘‹ thank you for raising this, I can see why this would make
error customisation easier.

For a feature request to be accepted, we want to see some discussion on
the [https://forum.djangoproject.com/c/internals/5 forum] first to
confirm/validate the feature with the community and get some feedback (so
next steps here would be to take this to the forum).
I'll close the ticket for now, but if there is a community agreement for
this, you are welcome to come back linking the forum topic, so we can then
re-open it.
For more details, please see
[https://docs.djangoproject.com/en/stable/internals/contributing/bugs-and-
features/#requesting-features the documented guidelines for requesting
features] 👍
--
Ticket URL: <https://code.djangoproject.com/ticket/35532#comment:1>

Django

unread,
Jul 8, 2024, 4:32:39 AM7/8/24
to django-...@googlegroups.com
#35532: Allow customizing errors processing in BaseModelFormSet.validate_unique()
----------------------------------+--------------------------------------
Reporter: Christophe Henry | Owner: nobody
Type: New feature | Status: new
Component: Forms | Version: 5.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Changes (by Christophe Henry):

* resolution: wontfix =>
* status: closed => new

Comment:

Replying to [comment:1 Sarah Boyce]:

Hi Sarah,

[https://forum.djangoproject.com/t/allow-customizing-errors-processing-in-
basemodelformset-validate-unique/32589 So I did what you advised] but that
doesn't seem to attract much attention. In the meantime, I really need
this feature for a project. What should I do?
--
Ticket URL: <https://code.djangoproject.com/ticket/35532#comment:2>

Django

unread,
Jul 8, 2024, 7:33:10 AM7/8/24
to django-...@googlegroups.com
#35532: Allow customizing errors processing in BaseModelFormSet.validate_unique()
----------------------------------+--------------------------------------
Reporter: Christophe Henry | Owner: nobody
Type: New feature | Status: closed
Component: Forms | Version: 5.0
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Changes (by Sarah Boyce):

* resolution: => wontfix
* status: new => closed

Comment:

Replying to [comment:2 Christophe Henry]:
> [https://forum.djangoproject.com/t/allow-customizing-errors-processing-
in-basemodelformset-validate-unique/32589 So I did what you advised] but
that doesn't seem to attract much attention.

Thank you for doing so, lack of feedback can mean a few things (perhaps
there is limited interest of the feature, perhaps this needs to be
promoted more as it has gotten "lost", perhaps this needs more time).

> In the meantime, I really need this feature for a project. What should I
do?

Your proposed patch suggestion looks very similar to overwriting the
existing `get_unique_error_message` and `get_date_error_message` methods,
the added value is in customising whether the error is within
`NON_FIELD_ERRORS` or on a specific field from what I can see.

When I started to look into this, I noticed that
[https://github.com/django/django/blob/main/django/forms/models.py#L506-L515
BaseModelForm.validate_unique()] has a `_update_errors` processing step
which doesn't appear to be in `BaseModelFormSet.validate_unique()`. This
makes me think, how would we do this in a normal model form? Can we not do
this the same way in a model formset? Is that a bug?

I don't have time to play around with this, but I think if you investigate
or start asking questions from the angle of "I need to achieve this, how
can I do this? How would I do this for a model form?" on one of our
[https://www.djangoproject.com/community/ user support channels], you will
probably end up with (A) the work around that you need for your project
and (B) a conclusion as to whether a change in Django needs to happen.

I hope that helps. As we still don't have the community consensus that we
need to make this change yet, I am closing as wontfix
--
Ticket URL: <https://code.djangoproject.com/ticket/35532#comment:3>
Reply all
Reply to author
Forward
0 new messages