[Django] #33936: BaseModelForm.save() ValueError lacks useful information

8 views
Skip to first unread message

Django

unread,
Aug 17, 2022, 8:49:34 PM8/17/22
to django-...@googlegroups.com
#33936: BaseModelForm.save() ValueError lacks useful information
--------------------------------------+------------------------
Reporter: Josh Moore | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: dev
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
--------------------------------------+------------------------
We were hitting Airbrake errors in production where the only message
provided was "The <model> could not be changed because the data didn't
validate." This made it difficult to troubleshoot and debug the problem.
The error message would be more useful if it included information about
which specific form fields failed to validate and why.

I have prepared a patch which enhances the error message in the
BaseModelForm save() method by including the actual form errors in the
message, formatted as JSON.

This is my first time contributing to Django and using Trac, please
forgive any mistakes I made filling out this form.

--
Ticket URL: <https://code.djangoproject.com/ticket/33936>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 17, 2022, 8:52:39 PM8/17/22
to django-...@googlegroups.com
#33936: BaseModelForm.save() ValueError lacks useful information
----------------------------+--------------------------------------

Reporter: Josh Moore | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: dev
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
----------------------------+--------------------------------------
Description changed by Josh Moore:

Old description:

> We were hitting Airbrake errors in production where the only message
> provided was "The <model> could not be changed because the data didn't
> validate." This made it difficult to troubleshoot and debug the problem.
> The error message would be more useful if it included information about
> which specific form fields failed to validate and why.
>
> I have prepared a patch which enhances the error message in the
> BaseModelForm save() method by including the actual form errors in the
> message, formatted as JSON.
>
> This is my first time contributing to Django and using Trac, please
> forgive any mistakes I made filling out this form.

New description:

We were hitting Airbrake errors in production where the only message
provided was "The <model> could not be changed because the data didn't
validate." This made it difficult to troubleshoot and debug the problem.
The error message would be more useful if it included information about
which specific form fields failed to validate and why.

I have prepared a patch which enhances the error message in the
BaseModelForm save() method by including the actual form errors in the
message, formatted as JSON.

This is my first time contributing to Django and using Trac, please
forgive any mistakes I made filling out this form.

PR containing my fix: https://github.com/django/django/pull/15968

--

--
Ticket URL: <https://code.djangoproject.com/ticket/33936#comment:1>

Django

unread,
Aug 18, 2022, 12:01:44 AM8/18/22
to django-...@googlegroups.com
#33936: BaseModelForm.save() ValueError lacks useful information
----------------------------+--------------------------------------
Reporter: Josh Moore | Owner: nobody
Type: Bug | Status: closed
Component: Forms | Version: dev
Severity: Normal | Resolution: duplicate

Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
----------------------------+--------------------------------------
Changes (by Mariusz Felisiak):

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


Comment:

Duplicate of #9605. The
[http://docs.djangoproject.com/en/dev/topics/forms/#using-a-form-in-a-view
normal pattern] is to call `is_valid()` yourself first and not proceed
with an attempt to `save()` if the form hasn't validated.

--
Ticket URL: <https://code.djangoproject.com/ticket/33936#comment:2>

Reply all
Reply to author
Forward
0 new messages