mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Fixed #25081 -- Prevented DISTINCT ON ordering from being cleared in get().
Thanks to pdewacht for the patch.
This commit is contained in:
		| @@ -376,7 +376,7 @@ class QuerySet(object): | ||||
|         keyword arguments. | ||||
|         """ | ||||
|         clone = self.filter(*args, **kwargs) | ||||
|         if self.query.can_filter(): | ||||
|         if self.query.can_filter() and not self.query.distinct_fields: | ||||
|             clone = clone.order_by() | ||||
|         num = len(clone) | ||||
|         if num == 1: | ||||
|   | ||||
| @@ -129,3 +129,11 @@ class DistinctOnTests(TestCase): | ||||
|             qs, [self.p1_o2, self.p2_o1, self.p3_o1], | ||||
|             lambda x: x | ||||
|         ) | ||||
|  | ||||
|     def test_distinct_on_get_ordering_preserved(self): | ||||
|         """ | ||||
|         Ordering shouldn't be cleared when distinct on fields are specified. | ||||
|         refs #25081 | ||||
|         """ | ||||
|         staff = Staff.objects.distinct('name').order_by('name', '-organisation').get(name='p1') | ||||
|         self.assertEqual(staff.organisation, 'o2') | ||||
|   | ||||
		Reference in New Issue
	
	Block a user