From 99e7bba443e3ff1a115d930dbb6dfcf9bccb027c Mon Sep 17 00:00:00 2001 From: Sergey Fedoseev Date: Fri, 28 Jul 2017 17:42:52 +0500 Subject: [PATCH] Prevented query_utils.refs_expression() from looking for empty string in annotations map. --- django/db/models/query_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django/db/models/query_utils.py b/django/db/models/query_utils.py index 0fedfac3e2d..e3f6a730d57 100644 --- a/django/db/models/query_utils.py +++ b/django/db/models/query_utils.py @@ -258,7 +258,7 @@ def refs_expression(lookup_parts, annotations): Because the LOOKUP_SEP is contained in the default annotation names, check each prefix of the lookup_parts for a match. """ - for n in range(len(lookup_parts) + 1): + for n in range(1, len(lookup_parts) + 1): level_n_lookup = LOOKUP_SEP.join(lookup_parts[0:n]) if level_n_lookup in annotations and annotations[level_n_lookup]: return annotations[level_n_lookup], lookup_parts[n:]