Opened 3 years ago

Closed 3 years ago

Last modified 3 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 Elvard 3 years ago.
Improved documentation
18996-2.diff (1.7 KB) - added by Elvard 3 years ago.
save(), pre_save and post_save are not called
18996-3.diff (1.2 KB) - added by timo 3 years ago.
Minor tweaks to last patch

Download all attachments as: .zip

Change History (12)

comment:1 Changed 3 years ago by ptone

  • Needs documentation set
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from Overriding predefined model methods vs bulk update. to better document overridden model save not called on bulk update.
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Uncategorized to Cleanup/optimization

Changed 3 years ago by Elvard

Improved documentation

comment:2 Changed 3 years ago by Elvard

  • Has patch set

comment:3 Changed 3 years ago by akaariai

  • 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 3 years ago by Elvard

save(), pre_save and post_save are not called

comment:4 Changed 3 years ago by Elvard

  • Cc tomas.ehrlich@… added

Changed 3 years ago by timo

Minor tweaks to last patch

comment:5 Changed 3 years ago by timo

  • Patch needs improvement unset

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

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

In 443999a1eeea70e4deebcf31f8f845696be62c3d:

Fixed #18996 - Docs on overriden model methods

comment:8 Changed 3 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 3 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