Code

Opened 5 years ago

Closed 5 years ago

Last modified 3 years ago

#10138 closed (fixed)

Documentation should mention that loaddata does not call custom save or pre_save signals

Reported by: varikin Owned by: kkubasik
Component: Documentation Version: master
Severity: Keywords: kkmegapatch
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

I have a custom save() method on a model, and I realized it isn't called during the loaddata. The loaddata command creates a set of DeserializedObject objects, each of which contain an object being loaded from the fixture. According to the DeserializedObject.save() method:

def save(self, save_m2m=True):
  # Call save on the Model baseclass directly. This bypasses any
  # model-defined save. The save is also forced to be raw.
  # This ensures that the data that is deserialized is literally
  # what came from the file, not post-processed by pre_save/save
  # methods.
  models.Model.save_base(self.object, raw=True)

In my case, I would like my save method on my model called, but that is easy to remedy for a one time load. In either case, it would be nice to have this documented.

I also found ticket #8399 which talks about the post_save signal being called. I don't know if it is just the pre_save signal and model's save methods not called, but post_save is. Or post_save isn't anymore and that is an old ticket that can be closed.

I will try to write a doc patch soon unless someone else beats me to it.

Attachments (1)

patch-10138.diff (725 bytes) - added by varikin 5 years ago.
docs patch

Download all attachments as: .zip

Change History (6)

Changed 5 years ago by varikin

docs patch

comment:1 Changed 5 years ago by varikin

  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

I took a first stab at adding the documentation. I would like someone who understands the internals better glance over it to see I described it correctly.

comment:2 Changed 5 years ago by jacob

  • milestone set to 1.1
  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 5 years ago by kkubasik

  • Keywords kkmegapatch added
  • Owner changed from nobody to kkubasik

comment:4 Changed 5 years ago by jacob

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

Fixed by [10303].

comment:5 Changed 3 years ago by jacob

  • milestone 1.1 deleted

Milestone 1.1 deleted

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.