Skip to content

Commit

Permalink
Bug Fix: the CONTAINS and NOT_CONTAINS operators cannot compare again…
Browse files Browse the repository at this point in the history
…st sets
  • Loading branch information
jpinner-lyft committed Aug 18, 2017
1 parent ea2a2ee commit 6262bf7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
16 changes: 12 additions & 4 deletions pynamodb/models.py
Expand Up @@ -32,7 +32,7 @@
CAPACITY_UNITS, META_CLASS_NAME, REGION, HOST, EXISTS, NULL,
DELETE_FILTER_OPERATOR_MAP, UPDATE_FILTER_OPERATOR_MAP, PUT_FILTER_OPERATOR_MAP,
COUNT, ITEM_COUNT, KEY, UNPROCESSED_ITEMS, STREAM_VIEW_TYPE, STREAM_SPECIFICATION,
STREAM_ENABLED, EQ, NE)
STREAM_ENABLED, EQ, NE, BINARY_SET, STRING_SET, NUMBER_SET)


log = logging.getLogger(__name__)
Expand Down Expand Up @@ -1057,9 +1057,17 @@ def _build_filters(cls,
else:
if not isinstance(value, list):
value = [value]
value = [
{ATTR_TYPE_MAP[attribute_class.attr_type]: attribute_class.serialize(val)} for val in value
]
attr_type = attribute_class.attr_type
if operator in ['contains', 'not_contains'] and attr_type in [BINARY_SET, STRING_SET, NUMBER_SET]:
# The 'CONTAINS' and 'NOT_CONTAINS' comparison operators do not support a set in ATTR_VALUE_LIST.
# If the `attribute_class` to serialize is a set, take the first element of type and value.
value = [
{ATTR_TYPE_MAP[attr_type][0]: attribute_class.serialize(val)[0]} for val in value
]
else:
value = [
{ATTR_TYPE_MAP[attr_type]: attribute_class.serialize(val)} for val in value
]
condition = {
ATTR_VALUE_LIST: value
}
Expand Down
2 changes: 1 addition & 1 deletion pynamodb/tests/test_model.py
Expand Up @@ -2674,7 +2674,7 @@ def test_index_queries(self):
'aliases': {
'AttributeValueList': [
{
'SS': ['1']
'S': '1'
}
],
'ComparisonOperator': 'CONTAINS'
Expand Down

0 comments on commit 6262bf7

Please sign in to comment.