summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorAttila Tovt <uran198@gmail.com>2015-11-22 02:59:37 +0200
committerTim Graham <timograham@gmail.com>2015-11-25 16:53:27 -0500
commit3ec4e739dd4ac3f1dea92cdec858bf491f63d5e8 (patch)
tree40a2114d70fad9750d2f9af1b75089c5dd9c190b /django
parent78627091f890061831f29085c5c5b47036be5cc6 (diff)
[1.8.x] Fixed #25772 -- Corrected __len lookup on ArrayField for empty arrays.
Backport of 88fc9e2826044110b7b22577a227f122fe9c1fb5 from master
Diffstat (limited to 'django')
-rw-r--r--django/contrib/postgres/fields/array.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/django/contrib/postgres/fields/array.py b/django/contrib/postgres/fields/array.py
index 87760613fb..ceac798604 100644
--- a/django/contrib/postgres/fields/array.py
+++ b/django/contrib/postgres/fields/array.py
@@ -198,7 +198,11 @@ class ArrayLenTransform(Transform):
def as_sql(self, compiler, connection):
lhs, params = compiler.compile(self.lhs)
- return 'array_length(%s, 1)' % lhs, params
+ # Distinguish NULL and empty arrays
+ return (
+ 'CASE WHEN %(lhs)s IS NULL THEN NULL ELSE '
+ 'coalesce(array_length(%(lhs)s, 1), 0) END'
+ ) % {'lhs': lhs}, params
class IndexTransform(Transform):