1
0
mirror of https://github.com/django/django.git synced 2025-10-26 15:16:09 +00:00

Fixed #25772 -- Corrected __len lookup on ArrayField for empty arrays.

This commit is contained in:
Attila Tovt
2015-11-22 02:59:37 +02:00
committed by Tim Graham
parent a3708fda35
commit 88fc9e2826
3 changed files with 15 additions and 1 deletions

View File

@@ -202,7 +202,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):