From bcce6bb7c7c494905b516cbed576f2fd0282e6f1 Mon Sep 17 00:00:00 2001 From: Josh Smeaton Date: Sat, 14 Jan 2017 13:12:24 +1100 Subject: [PATCH] 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. --- tests/queries/tests.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/queries/tests.py b/tests/queries/tests.py index 8f0af65c8d..b0999be3f8 100644 --- a/tests/queries/tests.py +++ b/tests/queries/tests.py @@ -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): [''] ) 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(