Skip to content

Commit 3dbb404

Browse files
author
Eric Muller
committed
Fix Query fails with more than 10 attributes in a query filter condition. (#751)
1 parent 5426ed9 commit 3dbb404

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

pynamodb/connection/base.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import json
77
import logging
88
import random
9+
import re
910
import sys
1011
import time
1112
import uuid
@@ -1240,11 +1241,12 @@ def query(self,
12401241
# FilterExpression does not allow key attributes. Check for hash and range key name placeholders
12411242
hash_key_placeholder = name_placeholders.get(hash_keyname)
12421243
range_key_placeholder = range_keyname and name_placeholders.get(range_keyname)
1243-
if (
1244-
hash_key_placeholder in filter_expression or
1245-
(range_key_placeholder and range_key_placeholder in filter_expression)
1246-
):
1247-
raise ValueError("'filter_condition' cannot contain key attributes")
1244+
if re.search(hash_key_placeholder + r"\D", filter_expression):
1245+
raise ValueError("'filter_condition' cannot contain hash key. {} found in {}"
1246+
.format(hash_key_placeholder, filter_expression))
1247+
if range_key_placeholder and re.search(range_key_placeholder + r"\D", filter_expression):
1248+
raise ValueError("'filter_condition' cannot contain range key. {} found in {}"
1249+
.format(range_key_placeholder, filter_expression))
12481250
operation_kwargs[FILTER_EXPRESSION] = filter_expression
12491251
if attributes_to_get:
12501252
projection_expression = create_projection_expression(attributes_to_get, name_placeholders)

0 commit comments

Comments
 (0)