Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed test failure caused by different NULL ordering between backends

  • Loading branch information...
commit 8dc76c4b9108f49afc5db07a23f34ad259a7642b 1 parent 9054098
Anssi Kääriäinen authored August 20, 2013
3  django/db/backends/__init__.py
@@ -595,6 +595,9 @@ class BaseDatabaseFeatures(object):
595 595
     # to remove any ordering?
596 596
     requires_explicit_null_ordering_when_grouping = False
597 597
 
  598
+    # Does the backend order NULL values as largest or smallest?
  599
+    nulls_order_largest = False
  600
+
598 601
     # Is there a 1000 item limit on query parameters?
599 602
     supports_1000_query_parameters = True
600 603
 
1  django/db/backends/postgresql_psycopg2/base.py
@@ -55,6 +55,7 @@ class DatabaseFeatures(BaseDatabaseFeatures):
55 55
     supports_tablespaces = True
56 56
     supports_transactions = True
57 57
     can_distinct_on_fields = True
  58
+    nulls_order_largest = True
58 59
 
59 60
 
60 61
 class DatabaseWrapper(BaseDatabaseWrapper):
4  tests/queries/models.py
@@ -262,9 +262,13 @@ def __str__(self):
262 262
         return self.name
263 263
 
264 264
 # A simpler shared-foreign-key setup that can expose some problems.
  265
+@python_2_unicode_compatible
265 266
 class SharedConnection(models.Model):
266 267
     data = models.CharField(max_length=10)
267 268
 
  269
+    def __str__(self):
  270
+        return self.data
  271
+
268 272
 class PointerA(models.Model):
269 273
     connection = models.ForeignKey(SharedConnection)
270 274
 
8  tests/queries/tests.py
@@ -2984,7 +2984,11 @@ def test_ticket_14056(self):
2984 2984
         s2 = SharedConnection.objects.create(data='s2')
2985 2985
         s3 = SharedConnection.objects.create(data='s3')
2986 2986
         PointerA.objects.create(connection=s2)
  2987
+        expected_ordering = (
  2988
+            [s1, s3, s2] if connection.features.nulls_order_largest
  2989
+            else [s2, s1, s3]
  2990
+        )
2987 2991
         self.assertQuerysetEqual(
2988  
-            SharedConnection.objects.order_by('pointera__connection', 'pk'),
2989  
-            [s1, s3, s2], lambda x: x
  2992
+            SharedConnection.objects.order_by('-pointera__connection', 'pk'),
  2993
+            expected_ordering, lambda x: x
2990 2994
         )

0 notes on commit 8dc76c4

Please sign in to comment.
Something went wrong with that request. Please try again.