Changes between Initial Version and Version 1 of Ticket #12149


Ignore:
Timestamp:
Nov 4, 2009, 7:18:33 AM (15 years ago)
Author:
Karen Tracey
Comment:

(Fixed formatting. Note you've got to put a space before the 1. in your lists to get them to format properly.)

The signals doc: http://docs.djangoproject.com/en/dev/ref/signals/#module-django.db.models.signals

notes that if you override save() you must call the parent class method in order for the signals to be sent. That makes it pretty clear the parent class code is what is going to send the signals. It isn't clear to me how you expect a signal to get sent at step 2 here:

  1. call overridden save method
  2. call pre_save
  3. set name to "dont_save".

At that point execution is in your own code, how is Django supposed to cause a signal to be sent?

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #12149

    • Property Resolutioninvalid
    • Property Status newclosed
  • Ticket #12149 – Description

    initial v1  
    2222In the above case, the flow goes like this
    2323
    24 1. call overridden save method
    25 1. check the condition in save method (condition is false)
    26 1. call super
    27 1. call pre_save
    28 1. set name to "dont_save"
    29 1. object saved to database with name = "dont_save"
     24 1. call overridden save method
     25 1. check the condition in save method (condition is false)
     26 1. call super
     27 1. call pre_save
     28 1. set name to "dont_save"
     29 1. object saved to database with name = "dont_save"
    3030
    3131This is rather unintuitive that the pre_save gets called in the middle of the save method. Also, any processing done in the pre_save cannot be handled in the save method as the flow has gone to the super class by then.
     
    3333The expected flow should be like this
    3434
    35 1. call overridden save method
    36 1. call pre_save
    37 1. set name to "dont_save"
    38 1. execution enters save method
    39 1. check condition in overridden save method (condition is true)
    40 1. return without saving
     35 1. call overridden save method
     36 1. call pre_save
     37 1. set name to "dont_save"
     38 1. execution enters save method
     39 1. check condition in overridden save method (condition is true)
     40 1. return without saving
Back to Top