From eaa07b1ccbf8291aa99e064c67089edd2715e953 Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Mon, 14 Sep 2015 14:13:06 +0200 Subject: [PATCH] ClipManager: match annotation layer case-sensitively (fixes #2832) The case must be correct anyway for the layer to be found in settings.CONFIG['layers']. Running this: Q(annotation__layer__iexact='foo') & Q(annotation__findvalue__icontains='bar') compiles to upper(layer) = upper('foo') and ... which can't use the case-sensitive annotation_annotation_layer index. This: Q(annotation__layer__exact='foo') & Q(annotation__findvalue__icontains='bar') can. (It still can't use the findvalue_like index, though! The other option is to add indices on upper(layer) and upper(findvalue) [varchar_pattern_ops].) --- pandora/clip/managers.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandora/clip/managers.py b/pandora/clip/managers.py index f4a09f7c..65ff43bf 100644 --- a/pandora/clip/managers.py +++ b/pandora/clip/managers.py @@ -44,7 +44,7 @@ def parseCondition(condition, user): 'operator': op}, user) \ & parseCondition({'key': 'annotations__layer', 'value': k, - 'operator': '=='}, user) + 'operator': '==='}, user) if op.startswith('!'): op = op[1:] @@ -82,6 +82,7 @@ def parseCondition(condition, user): '>=': '__gte', '<': '__lt', '<=': '__lte', + '===': '__exact', '==': '__iexact', '=': '__icontains', '^': '__istartswith', @@ -89,7 +90,7 @@ def parseCondition(condition, user): }.get(op, '__icontains')) key = str(key) - if isinstance(v, unicode): + if isinstance(v, unicode) and op != '===': v = unicodedata.normalize('NFKD', v).lower() if exclude: q = ~Q(**{key: v})