﻿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
27350	Attaching signals to abstract models don't work as it used to be	Florent Messa	nobody	"Hi,

I'm currently porting an application from Django 1.9.x to 1.10.x, we are relying on managers to attach signals to allow developers overriding them in our generic applications, this does not work anymore.

A complete example:


{{{
from django.db import models
from django.db.models import signals


class Poll(models.Model):
    question = models.CharField(max_length=255)
    answers_count = models.PositiveIntegerField(default=0)


class AnswerManager(models.Manager):
    def contribute_to_class(self, cls, name):
        signals.post_save.connect(self.post_save, sender=cls)

        return super(AnswerManager, self).contribute_to_class(cls, name)

    def post_save(self, instance, **kwargs):
        poll = instance.poll
        poll.answers_count = poll.answers.count()
        poll.save(update_fields=('answers_count', ))


class AbstractAnswer(models.Model):
    text = models.CharField(max_length=255)
    poll = models.ForeignKey(Poll, related_name='answers')

    objects = AnswerManager()

    class Meta:
        abstract = True


class Answer(AbstractAnswer):
    class Meta:
        abstract = False


class ModelsTests(TestCase):
    def test_simple_compute(self):
        poll = Poll.objects.create(question='Weird?')

        Answer.objects.create(poll=poll, text='Yes')

        # refresh
        poll = Poll.objects.get(pk=poll.pk)

        # still 0 on Django 1.10 and 1 on Django 1.9
        assert poll.answers_count == 1
}}}


The complete application is available [[https://github.com/thoas/django-signals-wtf|here]] and travis is available [[https://travis-ci.org/thoas/django-signals-wtf/builds/167669153|here]] to test again both 1.10 and 1.9.

Is this some kind of undocumented new behavior or a bug?"	Bug	closed	Database layer (models, ORM)	1.10	Normal	needsinfo		Loic Bistuer	Unreviewed	0	0	0	0	0	0
