﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
12149	pre_save is not called before the overridden save() method on a model	siddhi	nobody	"If I have a model where I override the save() method, then the pre_save signal is not sent before the save method is called.

Example:

{{{
class MyModel(models.Model):
    name = models.CharField(max_length=20)

    def save(self, force_insert=False, force_update=False):
        if self.name == ""dont_save"":
            return
        super(Project, self).save(force_insert, force_delete)
}}}

{{{
def presave_handler(sender, instance, **kwargs):
    instance.name = ""dont_save""

signals.pre_save.connect(presave_handler, sender=MyModel, dispatch_uid=""abc"")
}}}

In the above case, the flow goes like this

1. call overridden save method
1. check the condition in save method (condition is false)
1. call super
1. call pre_save
1. set name to ""dont_save""
1. object saved to database with name = ""dont_save""

This 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.

The expected flow should be like this

1. call overridden save method
1. call pre_save
1. set name to ""dont_save""
1. execution enters save method
1. check condition in overridden save method (condition is true)
1. return without saving
"		new	Uncategorized	1.1					Unreviewed	0	0	0	0	0	0
