pre_remove and post_remove "actions" not sent via m2m_changed signalling?

269 views
Skip to first unread message

Jeff Blaine

unread,
Jan 18, 2012, 11:47:27 AM1/18/12
to django...@googlegroups.com
Hi all,

http://dpaste.org/1vhf6/ 

With the following models.py, and the output seen further
down, can anyone explain why pre_remove and post_remove
"actions" are not happening when I remove an item from
a M2M relation?

class Interface(models.Model):
    name = models.CharField('Interface',
                            primary_key=True,
                            max_length=80)

class Netgroup(models.Model):
    name = models.CharField('Netgroup',
                            primary_key=True,
                            max_length=80)

    interfaces = models.ManyToManyField(Interface,
                                        null=True,
                                        blank=True)

    def __unicode__(self):
        return self.name

from django.db.models.signals import m2m_changed

def tester(sender, **kwargs):
    action = kwargs['action']
    instance = kwargs['instance']
    pk_set = kwargs['pk_set']
    model = kwargs['model']
    fd = open('/tmp/m2m.log', 'a+')
    fd.write('%s on %s pk_set of %s is %s\n' % (action, instance, model, str(pk_set)))
    fd.close()

m2m_changed.connect(tester, dispatch_uid="whatever")

#===============================================================
#
# IN ADMIN UI: Removed 'barley.foo.org' from jbtest2 which
#              had 4 interfaces (and then has 3, correctly)
#
#              Logs the following...
#
#              Where's the "remove" actions?
#
#===============================================================

pre_clear on instance jbtest2: pk_set of <class 'hostdb.models.Interface'> is None
post_clear on instance jbtest2: pk_set of <class 'hostdb.models.Interface'> is None
pre_add on instance jbtest2: pk_set of <class 'hostdb.models.Interface'> is set([u'babylon.foo.org', u'ape.foo.org', u'baker.foo.org'])
post_add on instance jbtest2: pk_set of <class 'hostdb.models.Interface'> is set([u'babylon.foo.org', u'ape.foo.org', u'baker.foo.org']) 

Jeff Blaine

unread,
Jan 18, 2012, 6:43:30 PM1/18/12
to django...@googlegroups.com
Answering my own question:  https://code.djangoproject.com/ticket/16073

:(

Thanks to IRC #django-users : carljm and domguard
Reply all
Reply to author
Forward
0 new messages