Opened 2 years ago

Closed 2 years ago

#33936 closed Bug (duplicate)

BaseModelForm.save() ValueError lacks useful information

Reported by: Josh Moore Owned by: nobody
Component: Forms Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description (last modified by Josh Moore)

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

Change History (2)

comment:1 by Josh Moore, 2 years ago

Description: modified (diff)

comment:2 by Mariusz Felisiak, 2 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #9605. The normal pattern is to call is_valid() yourself first and not proceed with an attempt to save() if the form hasn't validated.

Note: See TracTickets for help on using tickets.
Back to Top