Changed a test to be consistent when run in parallel.
This particular test was sometimes failing when running the test suite
in parallel. The `id` was different depending on the order the tests
were run. The test was incorrectly comparing model primary keys rather
than ensuring they didn't change.
@@ -1645,6 +1645,8 @@ class Queries5Tests(TestCase):
def test_ticket9848(self):
# Make sure that updates which only filter on sub-tables don't
# inadvertently update the wrong records (bug #9848).
+ author_start = Author.objects.get(name='a1')
+ ranking_start = Ranking.objects.get(author__name='a1')
# Make sure that the IDs from different tables don't happen to match.
self.assertQuerysetEqual(
@@ -1652,12 +1654,14 @@ class Queries5Tests(TestCase):
['<Ranking: 3: a1>']
)
self.assertEqual(
- Ranking.objects.filter(author__name='a1').update(rank='4'),
+ Ranking.objects.filter(author__name='a1').update(rank=4636),
1
)
- r = Ranking.objects.filter(author__name='a1')[0]
- self.assertNotEqual(r.id, r.author.id)
- self.assertEqual(r.rank, 4)
+
+ r = Ranking.objects.get(author__name='a1')
+ self.assertEqual(r.id, ranking_start.id)
+ self.assertEqual(r.author.id, author_start.id)
+ self.assertEqual(r.rank, 4636)
r.rank = 3
r.save()
self.assertQuerysetEqual(
