duplicate post_save signals

827 views
Skip to first unread message

Kenneth Gonsalves

unread,
Aug 18, 2010, 2:48:51 AM8/18/10
to Django users
hi,

I am using a two post_save signal handlers for two different models. On
certain conditions they have to send emails to me and others. At times
one signal is generated, at other times two or even in one instance 4
signals were generated, which results in duplicate and triplicate
emails. Has anyone faced this problem?
--
regards
Kenneth Gonsalves

Sam Lai

unread,
Aug 18, 2010, 3:16:41 AM8/18/10
to django...@googlegroups.com
I was looking at this over the weekend as well; isn't a problem for me
but it seems that the post_save signal is triggered even when
commit=False. Therefore when the object is saved again with
commit=True, it is fired again.

I didn't really investigate this so I could be wrong, but might be
something worth looking at.

> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to django-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>
>

Kenneth Gonsalves

unread,
Aug 18, 2010, 3:28:21 AM8/18/10
to django...@googlegroups.com
On Wed, 2010-08-18 at 17:16 +1000, Sam Lai wrote:
> I was looking at this over the weekend as well; isn't a problem for me
> but it seems that the post_save signal is triggered even when
> commit=False. Therefore when the object is saved again with
> commit=True, it is fired again.
>
> I didn't really investigate this so I could be wrong, but might be
> something worth looking at.

well, in one model I am saving twice - so at least that is logical. But
in the other, there is just one save - no commit=false. I read somewhere
long time back that when a model is updated, django saves it twice. In
which case it would be logical?

>
> On 18 August 2010 16:48, Kenneth Gonsalves <law...@au-kbc.org> wrote:
> > hi,
> >
> > I am using a two post_save signal handlers for two different models. On
> > certain conditions they have to send emails to me and others. At times
> > one signal is generated, at other times two or even in one instance 4
> > signals were generated, which results in duplicate and triplicate
> > emails. Has anyone faced this problem?
> > --
> > regards
> > Kenneth Gonsalves
> >
> > --
> > You received this message because you are subscribed to the Google Groups "Django users" group.
> > To post to this group, send email to django...@googlegroups.com.
> > To unsubscribe from this group, send email to django-users...@googlegroups.com.
> > For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
> >
> >
>


--
regards
Kenneth Gonsalves

David De La Harpe Golden

unread,
Aug 18, 2010, 7:00:30 AM8/18/10
to django...@googlegroups.com, Kenneth Gonsalves


Just in case - you have set a dispatch_uid during signal connection
so they're only registered once?

You probably have your signal connections at module scope
(e.g. we tend to do them in apps' __init__.py to make sure they're
connected early), and you don't dispatch_uid them, you'll find that just
by virtue of double imports and whatnot sometimes you get duplicate
registrations which cause them to fire twice.

signals.post_save.connect(_do_thingy, sender=Blah, dispatch_uid="mymodule")

Not all the docs mention dispatch_uid, which doesn't help, it's
mentioned here:

http://code.djangoproject.com/wiki/Signals#Helppost_saveseemstobeemittedtwiceforeachsave

Kenneth Gonsalves

unread,
Aug 18, 2010, 7:14:27 AM8/18/10
to django...@googlegroups.com
On Wed, 2010-08-18 at 12:00 +0100, David De La Harpe Golden wrote:
> > I am using a two post_save signal handlers for two different models.
> On
> > certain conditions they have to send emails to me and others. At
> times
> > one signal is generated, at other times two or even in one instance
> 4
> > signals were generated, which results in duplicate and triplicate
> > emails. Has anyone faced this problem?
>
>
> Just in case - you have set a dispatch_uid during signal connection
> so they're only registered once?
>
> You probably have your signal connections at module scope
> (e.g. we tend to do them in apps' __init__.py to make sure they're
> connected early), and you don't dispatch_uid them, you'll find that
> just
> by virtue of double imports and whatnot sometimes you get duplicate
> registrations which cause them to fire twice.
>
> signals.post_save.connect(_do_thingy, sender=Blah,
> dispatch_uid="mymodule")

yes - actually there was a double import - I removed it and also added
despatch_uid - looks like the problem is solved
--
regards
Kenneth Gonsalves

Reply all
Reply to author
Forward
0 new messages