From a699595fce27d5d9c45ba83c656319593c366be9 Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Thu, 31 Oct 2019 15:17:04 -0400 Subject: [PATCH] Refs #13312 -- Removed unnecessary IF wrapping in nulls_last handling on MySQL. ISNULL function already returns 0 and 1 on MySQL. --- django/db/models/expressions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django/db/models/expressions.py b/django/db/models/expressions.py index 2eae16541e..44a52c1dc9 100644 --- a/django/db/models/expressions.py +++ b/django/db/models/expressions.py @@ -1156,7 +1156,7 @@ class OrderBy(BaseExpression): def as_mysql(self, compiler, connection): template = None if self.nulls_last: - template = 'IF(ISNULL(%(expression)s),1,0), %(expression)s %(ordering)s ' + template = 'ISNULL(%(expression)s), %(expression)s %(ordering)s ' elif self.nulls_first: template = 'IF(ISNULL(%(expression)s),0,1), %(expression)s %(ordering)s ' return self.as_sql(compiler, connection, template=template)