diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index f4bf8b2..76d8496 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -1431,7 +1431,7 @@ class BaseQuery(object):
             #   - this is an annotation over a model field
             # then we need to explore the joins that are required.
 
-            field, source, opts, join_list, last, _ = self.setup_joins(
+            field, source, opts, join_list, last, extra = self.setup_joins(
                 field_list, opts, self.get_initial_alias(), False)
 
             # Process the join chain to see if it can be trimmed
@@ -1444,6 +1444,9 @@ class BaseQuery(object):
                 self.promote_alias(column_alias, unconditional=True)
 
             col = (join_list[-1], col)
+            for filter in extra:
+                self.add_filter(filter, can_reuse=set(join_list),
+                    process_extras=False)
         else:
             # The simplest cases. No joins required -
             # just reference the provided column alias.
diff --git a/tests/regressiontests/aggregation_regress/models.py b/tests/regressiontests/aggregation_regress/models.py
index d1f1451..a8b09a8 100644
--- a/tests/regressiontests/aggregation_regress/models.py
+++ b/tests/regressiontests/aggregation_regress/models.py
@@ -3,6 +3,8 @@ import pickle
 
 from django.db import models
 from django.conf import settings
+from django.contrib.contenttypes import generic
+from django.contrib.contenttypes.models import ContentType
 
 try:
     sorted
@@ -34,6 +36,7 @@ class Book(models.Model):
     contact = models.ForeignKey(Author, related_name='book_contact_set')
     publisher = models.ForeignKey(Publisher)
     pubdate = models.DateField()
+    tags = generic.GenericRelation('TaggedItem')
 
     class Meta:
         ordering = ('name',)
@@ -66,6 +69,16 @@ class HardbackBook(Book):
     def __unicode__(self):
         return "%s (hardback): %s" % (self.name, self.weight)
 
+class TaggedItem(models.Model):
+    tag = models.CharField(max_length=100)
+    content_type = models.ForeignKey(ContentType, related_name="aggregation_tagged_item_set")
+    object_id = models.PositiveIntegerField()
+    content_object = generic.GenericForeignKey('content_type', 'object_id')
+
+    def __unicode__(self):
+        return "%s tagged with %s" % (self.content_object, self.tag)
+
+
 __test__ = {'API_TESTS': """
 >>> from django.core import management
 >>> from django.db.models import get_app, F
@@ -145,17 +158,17 @@ __test__ = {'API_TESTS': """
 >>> Book.objects.all().aggregate(num_authors=Count('foo'))
 Traceback (most recent call last):
 ...
-FieldError: Cannot resolve keyword 'foo' into field. Choices are: authors, contact, hardbackbook, id, isbn, name, pages, price, pubdate, publisher, rating, store
+FieldError: Cannot resolve keyword 'foo' into field. Choices are: authors, contact, hardbackbook, id, isbn, name, pages, price, pubdate, publisher, rating, store, tags
 
 >>> Book.objects.all().annotate(num_authors=Count('foo'))
 Traceback (most recent call last):
 ...
-FieldError: Cannot resolve keyword 'foo' into field. Choices are: authors, contact, hardbackbook, id, isbn, name, pages, price, pubdate, publisher, rating, store
+FieldError: Cannot resolve keyword 'foo' into field. Choices are: authors, contact, hardbackbook, id, isbn, name, pages, price, pubdate, publisher, rating, store, tags
 
 >>> Book.objects.all().annotate(num_authors=Count('authors__id')).aggregate(Max('foo'))
 Traceback (most recent call last):
 ...
-FieldError: Cannot resolve keyword 'foo' into field. Choices are: authors, contact, hardbackbook, id, isbn, name, pages, price, pubdate, publisher, rating, store, num_authors
+FieldError: Cannot resolve keyword 'foo' into field. Choices are: authors, contact, hardbackbook, id, isbn, name, pages, price, pubdate, publisher, rating, store, tags, num_authors
 
 # Old-style count aggregations can be mixed with new-style
 >>> Book.objects.annotate(num_authors=Count('authors')).count()
@@ -317,7 +330,22 @@ True
 Traceback (most recent call last):
 ...
 FieldError: Cannot compute Avg('mean_age'): 'mean_age' is an aggregate
-
+>>> b = Book.objects.get(name='Practical Django Projects')
+>>> _ = TaggedItem.objects.create(object_id=b.id, content_type=ContentType.objects.get_for_model(b), tag='intermediate')
+>>> _ = TaggedItem.objects.create(object_id=b.id, content_type=ContentType.objects.get_for_model(b), tag='django')
+>>> b = Book.objects.get(name__startswith='Paradigms of Artificial Intelligence')
+>>> _ = TaggedItem.objects.create(object_id=b.id, content_type=ContentType.objects.get_for_model(b), tag='intermediate')
+
+>>> s = Store.objects.get(name__startswith='Amazon')
+>>> _ = TaggedItem.objects.create(object_id=s.id, content_type=ContentType.objects.get_for_model(s), tag='online')
+>>> Book.objects.aggregate(Count('tags'))
+{'tags__count': 3}
+
+>>> [(b.name, b.tags__count) for b in Book.objects.annotate(Count('tags')).order_by('-tags__count')[:2]]
+[(u'Practical Django Projects', 2), (u'Paradigms of Artificial Intelligence Programming: Case Studies in Common Lisp', 1)]
+>>> list(Book.objects.annotate(Count('tags')).order_by('name')) == list(Book.objects.order_by('name'))
+True
+>>> print Book.objects.annotate(Count('tags')).order_by('name').query
 """
 }
 
