diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index f4bf8b2..04796f2 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -1431,8 +1431,11 @@ 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)
+            # add any extra filters that are needed
+            if extra:
+                self.add_filter(*extra)
 
             # Process the join chain to see if it can be trimmed
             col, _, join_list = self.trim_joins(source, join_list, last, False)
diff --git a/tests/regressiontests/aggregation_regress/models.py b/tests/regressiontests/aggregation_regress/models.py
index d1f1451..e8e47b0 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)
+    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,21 @@ 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')
+>>> from django.conf import settings
+>>> settings.DEBUG = True
+>>> from django.db import connection, reset_queries
+>>> reset_queries()
+>>> Book.objects.aggregate(Count('tags'))
+{'tags__count': 3}
+>>> connection.queries
 """
 }
 
