diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index b6047febae..72948f9cd7 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -347,7 +347,9 @@ class SQLCompiler(object): elif not self.query.default_ordering: ordering = self.query.order_by else: - ordering = self.query.order_by or self.query.model._meta.ordering + ordering = (self.query.order_by + or self.query.model._meta.ordering + or []) qn = self.quote_name_unless_alias qn2 = self.connection.ops.quote_name distinct = self.query.distinct diff --git a/tests/regressiontests/queries/tests.py b/tests/regressiontests/queries/tests.py index 8e9705e9f7..ded3e8ffa7 100644 --- a/tests/regressiontests/queries/tests.py +++ b/tests/regressiontests/queries/tests.py @@ -830,6 +830,17 @@ class Queries1Tests(BaseQuerysetTest): 1 ) + def test_ticket17429(self): + """ + Ensure that Meta.ordering=None works the same as Meta.ordering=[] + """ + original_ordering = Tag._meta.ordering + Tag._meta.ordering = None + self.assertQuerysetEqual( + Tag.objects.all(), + ['', '', '', '', ''], + ) + Tag._meta.ordering = original_ordering class Queries2Tests(TestCase): def setUp(self):