Code

Opened 11 months ago

Closed 11 months ago

Last modified 11 months ago

#20859 closed Cleanup/optimization (fixed)

Example for Model.clean doesn't call parent method

Reported by: aaugustin Owned by: jimmysong
Component: Documentation Version: 1.5
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#overriding-the-clean-method warns that if one customizes the clean() method for a model, one should call the parent method to maintain default validation.

https://docs.djangoproject.com/en/dev/ref/models/instances/#django.db.models.Model.clean shows an example which doesn't call the parent method.

I think the example should be modified to take this best practice into account.

Attachments (0)

Change History (8)

comment:1 Changed 11 months ago by timo

  • Component changed from Uncategorized to Documentation
  • Easy pickings set
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Uncategorized to Cleanup/optimization

comment:2 Changed 11 months ago by jimmysong

  • Owner changed from nobody to jimmysong
  • Status changed from new to assigned

comment:3 Changed 11 months ago by jimmysong

  • Has patch set

Changed the example in the documentation. Pull request here: https://github.com/django/django/pull/1434

comment:4 Changed 11 months ago by jimmysong

fixed the tab indent issue in pull request.

comment:5 Changed 11 months ago by timo

The warning refers to ModelForm.clean() while the example is for Model.clean() which actually does not require calling super as it does nothing. That said, I think the patch does help clarify the example, so I'll merge it minus the super call.

comment:6 Changed 11 months ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In 94d7fed7750322e8b80402c1e731bab6d4509f2e:

Fixed #20859 - Clarified Model.clean() example.

comment:7 Changed 11 months ago by Tim Graham <timograham@…>

In ea7bef318fd42411e3db057e888367ef52fb23c3:

[1.6.x] Fixed #20859 - Clarified Model.clean() example.

Backport of 94d7fed775 from master

comment:8 Changed 11 months ago by aaugustin

Oops, sorry for the bad report :|

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.