[3.1.x] Fixed #31752 -- Fixed intermittent test_order_by_relational_field_through_model failure.

Set explicit datetime for M2M ordering test.

Thanks to Mariusz Felisiak for the suggestion.
Backport of b5371539a9 from master
This commit is contained in:
Carlton Gibson 2020-06-30 13:08:23 +02:00 committed by Mariusz Felisiak
parent 5460041475
commit 84640f5ae3
1 changed files with 7 additions and 5 deletions

View File

@ -1,4 +1,4 @@
from datetime import date, datetime from datetime import date, datetime, timedelta
from operator import attrgetter from operator import attrgetter
from django.db import IntegrityError from django.db import IntegrityError
@ -238,10 +238,12 @@ class M2mThroughTests(TestCase):
) )
def test_order_by_relational_field_through_model(self): def test_order_by_relational_field_through_model(self):
CustomMembership.objects.create(person=self.jim, group=self.rock) today = datetime.now()
CustomMembership.objects.create(person=self.bob, group=self.rock) yesterday = today - timedelta(days=1)
CustomMembership.objects.create(person=self.jane, group=self.roll) CustomMembership.objects.create(person=self.jim, group=self.rock, date_joined=yesterday)
CustomMembership.objects.create(person=self.jim, group=self.roll) CustomMembership.objects.create(person=self.bob, group=self.rock, date_joined=today)
CustomMembership.objects.create(person=self.jane, group=self.roll, date_joined=yesterday)
CustomMembership.objects.create(person=self.jim, group=self.roll, date_joined=today)
self.assertSequenceEqual( self.assertSequenceEqual(
self.rock.custom_members.order_by('custom_person_related_name'), self.rock.custom_members.order_by('custom_person_related_name'),
[self.jim, self.bob] [self.jim, self.bob]