#2626 - DynamoDB - FilterExpression should ignore items with non-existent attribute
This commit is contained in:
parent
74ad2d7d3c
commit
9ce1ee49d7
@ -979,8 +979,6 @@ class OpLessThan(Op):
|
|||||||
# In python3 None is not a valid comparator when using < or > so must be handled specially
|
# In python3 None is not a valid comparator when using < or > so must be handled specially
|
||||||
if lhs and rhs:
|
if lhs and rhs:
|
||||||
return lhs < rhs
|
return lhs < rhs
|
||||||
elif lhs is None and rhs:
|
|
||||||
return True
|
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -994,8 +992,6 @@ class OpGreaterThan(Op):
|
|||||||
# In python3 None is not a valid comparator when using < or > so must be handled specially
|
# In python3 None is not a valid comparator when using < or > so must be handled specially
|
||||||
if lhs and rhs:
|
if lhs and rhs:
|
||||||
return lhs > rhs
|
return lhs > rhs
|
||||||
elif lhs and rhs is None:
|
|
||||||
return True
|
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -1027,8 +1023,6 @@ class OpLessThanOrEqual(Op):
|
|||||||
# In python3 None is not a valid comparator when using < or > so must be handled specially
|
# In python3 None is not a valid comparator when using < or > so must be handled specially
|
||||||
if lhs and rhs:
|
if lhs and rhs:
|
||||||
return lhs <= rhs
|
return lhs <= rhs
|
||||||
elif lhs is None and rhs or lhs is None and rhs is None:
|
|
||||||
return True
|
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -1042,8 +1036,6 @@ class OpGreaterThanOrEqual(Op):
|
|||||||
# In python3 None is not a valid comparator when using < or > so must be handled specially
|
# In python3 None is not a valid comparator when using < or > so must be handled specially
|
||||||
if lhs and rhs:
|
if lhs and rhs:
|
||||||
return lhs >= rhs
|
return lhs >= rhs
|
||||||
elif lhs and rhs is None or lhs is None and rhs is None:
|
|
||||||
return True
|
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -1719,6 +1719,32 @@ def test_scan_filter4():
|
|||||||
assert response["Count"] == 0
|
assert response["Count"] == 0
|
||||||
|
|
||||||
|
|
||||||
|
@mock_dynamodb2
|
||||||
|
def test_scan_filter_should_not_return_non_existing_attributes():
|
||||||
|
table_name = "my-table"
|
||||||
|
item = {"partitionKey": "pk-2", "my-attr": 42}
|
||||||
|
# Create table
|
||||||
|
res = boto3.resource("dynamodb")
|
||||||
|
res.create_table(
|
||||||
|
TableName=table_name,
|
||||||
|
KeySchema=[{"AttributeName": "partitionKey", "KeyType": "HASH"}],
|
||||||
|
AttributeDefinitions=[{"AttributeName": "partitionKey", "AttributeType": "S"}],
|
||||||
|
BillingMode="PAY_PER_REQUEST",
|
||||||
|
)
|
||||||
|
table = res.Table(table_name)
|
||||||
|
# Insert items
|
||||||
|
table.put_item(Item={"partitionKey": "pk-1"})
|
||||||
|
table.put_item(Item=item)
|
||||||
|
# Verify a few operations
|
||||||
|
# Assert we only find the item that has this attribute
|
||||||
|
table.scan(FilterExpression=Attr("my-attr").lt(43))["Items"].should.equal([item])
|
||||||
|
table.scan(FilterExpression=Attr("my-attr").lte(42))["Items"].should.equal([item])
|
||||||
|
table.scan(FilterExpression=Attr("my-attr").gte(42))["Items"].should.equal([item])
|
||||||
|
table.scan(FilterExpression=Attr("my-attr").gt(41))["Items"].should.equal([item])
|
||||||
|
# Sanity check that we can't find the item if the FE is wrong
|
||||||
|
table.scan(FilterExpression=Attr("my-attr").gt(43))["Items"].should.equal([])
|
||||||
|
|
||||||
|
|
||||||
@mock_dynamodb2
|
@mock_dynamodb2
|
||||||
def test_bad_scan_filter():
|
def test_bad_scan_filter():
|
||||||
client = boto3.client("dynamodb", region_name="us-east-1")
|
client = boto3.client("dynamodb", region_name="us-east-1")
|
||||||
|
Loading…
Reference in New Issue
Block a user