Ticket #16955: 16955.diff

File 16955.diff, 4.8 KB (added by David Gouldin, 13 years ago)
  • django/db/models/sql/query.py

    diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
    index 61fd2be..6e7abc1 100644
    a b class Query(object):  
    10921092                    can_reuse)
    10931093            return
    10941094
     1095        from django.db.models.base import Model
     1096        from django.db.models.fields.related import RelatedField
     1097        if (isinstance(field, RelatedField) and isinstance(value, Model) and
     1098                not isinstance(value, target.model)):
     1099            raise TypeError, "'%s' instance expected" % target.model._meta.object_name
     1100
    10951101        table_promote = False
    10961102        join_promote = False
    10971103
  • tests/modeltests/many_to_many/tests.py

    diff --git a/tests/modeltests/many_to_many/tests.py b/tests/modeltests/many_to_many/tests.py
    index 39fe581..2479268 100644
    a b class ManyToManyTests(TestCase):  
    195195        self.assertQuerysetEqual(Article.objects.exclude(publications=self.p2),
    196196                                 ['<Article: Django lets you build Web apps easily>'])
    197197
     198        # Filter values on related fields are checked to ensure the correct
     199        # model class is being used.
     200        self.assertRaises(TypeError, Article.objects.filter,
     201            publications=self.a1)
     202
    198203    def test_reverse_selects(self):
    199204        # Reverse m2m queries are supported (i.e., starting at the table that
    200205        # doesn't have a ManyToManyField).
    class ManyToManyTests(TestCase):  
    245250                '<Publication: The Python Journal>',
    246251            ])
    247252
     253        # Filter values on related fields are checked to ensure the correct
     254        # model class is being used.
     255        self.assertRaises(TypeError, Publication.objects.filter,
     256             article=self.p1)
     257
    248258    def test_delete(self):
    249259        # If we delete a Publication, its Articles won't be able to access it.
    250260        self.p1.delete()
  • tests/modeltests/many_to_one/tests.py

    diff --git a/tests/modeltests/many_to_one/tests.py b/tests/modeltests/many_to_one/tests.py
    index 9f60c21..053c5ee 100644
    a b class ManyToOneTests(TestCase):  
    230230                "<Article: This is a test>",
    231231            ])
    232232
     233        # Filter values on related fields are checked to ensure the correct
     234        # model class is being used.
     235        self.assertRaises(TypeError, Article.objects.filter, reporter=self.a)
     236
    233237    def test_reverse_selects(self):
    234238        a3 = Article.objects.create(id=None, headline="Third article",
    235239                                    pub_date=datetime(2005, 7, 27), reporter_id=self.r.id)
    class ManyToOneTests(TestCase):  
    301305            list(Article.objects.filter(reporter=self.r).distinct().order_by()
    302306                 .values('reporter__first_name', 'reporter__last_name')))
    303307
     308        # Filter values on related fields are checked to ensure the correct
     309        # model class is being used.
     310        self.assertRaises(TypeError, Reporter.objects.filter, article=self.r)
     311
    304312    def test_select_related(self):
    305313        # Check that Article.objects.select_related().dates() works properly when
    306314        # there are multiple Articles with the same date but different foreign-key
  • tests/modeltests/one_to_one/tests.py

    diff --git a/tests/modeltests/one_to_one/tests.py b/tests/modeltests/one_to_one/tests.py
    index c3e1704..0e5724a 100644
    a b class OneToOneTests(TestCase):  
    6161        assert_get_restaurant(place__pk=self.p1.pk)
    6262        assert_get_restaurant(place__name__startswith="Demon")
    6363
     64        # Filter values on related fields are checked to ensure the correct
     65        # model class is being used.
     66        self.assertRaises(TypeError, Restaurant.objects.get, place=self.r)
     67
    6468        def assert_get_place(**params):
    6569            self.assertEqual(repr(Place.objects.get(**params)),
    6670                             '<Place: Demon Dogs the place>')
    class OneToOneTests(TestCase):  
    7579        assert_get_place(id__exact=self.p1.pk)
    7680        assert_get_place(pk=self.p1.pk)
    7781
     82        # Filter values on related fields are checked to ensure the correct
     83        # model class is being used.
     84        self.assertRaises(TypeError, Place.objects.get, restaurant=self.p1)
     85
    7886    def test_foreign_key(self):
    7987        # Add a Waiter to the Restaurant.
    8088        w = self.r.waiter_set.create(name='Joe')
    class OneToOneTests(TestCase):  
    8997        assert_filter_waiters(restaurant__place__exact=self.p1)
    9098        assert_filter_waiters(restaurant__place__pk=self.p1.pk)
    9199        assert_filter_waiters(restaurant__exact=self.p1.pk)
    92         assert_filter_waiters(restaurant__exact=self.p1)
    93100        assert_filter_waiters(restaurant__pk=self.p1.pk)
    94101        assert_filter_waiters(restaurant=self.p1.pk)
    95102        assert_filter_waiters(restaurant=self.r)
Back to Top