Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#18996 closed Cleanup/optimization (fixed)

better document overridden model save not called on bulk update.

Reported by: bram.dejong@… Owned by: nobody
Component: Documentation Version: 1.4
Severity: Normal Keywords: docs overriding save bulk update
Cc: tomas.ehrlich@… Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

The documentation on overriding predefined model methods should mention that bulk updates do no trigger customized save methods. I.e. if I do MyModel.objects.all().update(a=5) will not trigger MyModel.save().

The docs do already mention this in the description of update( ) but not in the description of overriding methods:
https://docs.djangoproject.com/en/dev/topics/db/models/#overriding-predefined-model-methods

Attachments (3)

18996-1.diff (1.4 KB) - added by Tomáš Ehrlich 4 years ago.
Improved documentation
18996-2.diff (1.7 KB) - added by Tomáš Ehrlich 4 years ago.
save(), pre_save and post_save are not called
18996-3.diff (1.2 KB) - added by Tim Graham 4 years ago.
Minor tweaks to last patch

Download all attachments as: .zip

Change History (12)

comment:1 Changed 4 years ago by Preston Holmes

Needs documentation: set
Summary: Overriding predefined model methods vs bulk update.better document overridden model save not called on bulk update.
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

Changed 4 years ago by Tomáš Ehrlich

Attachment: 18996-1.diff added

Improved documentation

comment:2 Changed 4 years ago by Tomáš Ehrlich

Has patch: set

comment:3 Changed 4 years ago by Anssi Kääriäinen

Patch needs improvement: set

The patch isn't correct - you can't use pre/post_save for update operations. In addition, bulk_create would be good to mention at the same time, too. It is a bit sad that there isn't anything you can use for .update() operations currently...

Changed 4 years ago by Tomáš Ehrlich

Attachment: 18996-2.diff added

save(), pre_save and post_save are not called

comment:4 Changed 4 years ago by Tomáš Ehrlich

Cc: tomas.ehrlich@… added

Changed 4 years ago by Tim Graham

Attachment: 18996-3.diff added

Minor tweaks to last patch

comment:5 Changed 4 years ago by Tim Graham

Patch needs improvement: unset

comment:6 Changed 4 years ago by Tomáš Ehrlich

comment:7 Changed 4 years ago by Tomáš Ehrlich <tomas.ehrlich@…>

Resolution: fixed
Status: newclosed

In 443999a1eeea70e4deebcf31f8f845696be62c3d:

Fixed #18996 - Docs on overriden model methods

comment:8 Changed 4 years ago by Tim Graham <timograham@…>

In 5fb22329a14695419f191da8b7d0b5b22793aff0:

Merge pull request #422 from elvard/18996

Fixed #18996 - Clarified overriden model methods not called on bulk operations

comment:9 Changed 4 years ago by Tim Graham <timograham@…>

In d2891d1c0751d53c10f19672ac7d232b6e5088b0:

[1.4.x] Fixed #18996 - Clarified overriden model methods not called on bulk operations

Backport of 443999a1eeea70e4deebcf31f8f845696be62c3d from master.

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