From 3898124112e81173887195a206ced17ae6cdbc62 Mon Sep 17 00:00:00 2001 From: Bert Blommers Date: Fri, 12 Nov 2021 20:09:03 -0100 Subject: [PATCH] DynamoDB - fix bugfix between 0 and x (#4567) --- moto/dynamodb2/comparisons.py | 6 +++++- tests/test_dynamodb2/test_dynamodb.py | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/moto/dynamodb2/comparisons.py b/moto/dynamodb2/comparisons.py index 260ae6857..a126ba9d3 100644 --- a/moto/dynamodb2/comparisons.py +++ b/moto/dynamodb2/comparisons.py @@ -1162,7 +1162,11 @@ class FuncBetween(Func): start = self.start.expr(item) attr = self.attr.expr(item) end = self.end.expr(item) - if start and attr and end: + # Need to verify whether start has a valid value + # Can't just check 'if start', because start could be 0, which is a valid integer + start_has_value = start is not None and (isinstance(start, int) or start) + end_has_value = end is not None and (isinstance(end, int) or end) + if start_has_value and attr and end_has_value: return start <= attr <= end elif start is None and attr is None: # None is between None and None as well as None is between None and any number diff --git a/tests/test_dynamodb2/test_dynamodb.py b/tests/test_dynamodb2/test_dynamodb.py index 272d7b628..ec9c1aadf 100644 --- a/tests/test_dynamodb2/test_dynamodb.py +++ b/tests/test_dynamodb2/test_dynamodb.py @@ -1551,6 +1551,12 @@ def test_filter_expression(): ) filter_expr.expr(row1).should.be(True) + # BETWEEN integer test + filter_expr = moto.dynamodb2.comparisons.get_filter_expression( + "Id BETWEEN :v0 AND :v1", {}, {":v0": {"N": "0"}, ":v1": {"N": "10"}} + ) + filter_expr.expr(row1).should.be(True) + # PAREN test filter_expr = moto.dynamodb2.comparisons.get_filter_expression( "Id = :v0 AND (Subs = :v0 OR Subs = :v1)",