From 6d4637de9751c7bc0369d8e2ecc4aa52b1a7ab3e Mon Sep 17 00:00:00 2001 From: Jonas Obrist Date: Tue, 9 Jan 2024 17:05:01 +0900 Subject: [PATCH 1/2] add test for attribute type filter --- tests/integration/test_client.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/integration/test_client.py b/tests/integration/test_client.py index 15fa250..769ab49 100644 --- a/tests/integration/test_client.py +++ b/tests/integration/test_client.py @@ -39,7 +39,7 @@ TimeToLiveStatus, ) from aiodynamo.operations import ConditionCheck, Delete, Get, Put, Update -from aiodynamo.types import TableName +from aiodynamo.types import AttributeType, TableName from tests.integration.conftest import TableFactory @@ -803,3 +803,15 @@ async def test_pay_per_request_table( assert not set(map(itemgetter("r"), first_page.items)) & set( map(itemgetter("r"), second_page.items) ) + + +async def test_attribute_type_filter(client: Client, table: TableName) -> None: + await client.put_item(table=table, item={"h": "h", "r": "1", "a": 1}) + await client.put_item(table=table, item={"h": "h", "r": "2", "a": "2"}) + items = { + item["r"] + async for item in client.scan( + table=table, filter_expression=F("a").attribute_type(AttributeType.string) + ) + } + assert items == {"2"} From 821255f18a3c5f5621b2b3117ac103fbeba89322 Mon Sep 17 00:00:00 2001 From: Jonas Obrist Date: Tue, 9 Jan 2024 17:05:24 +0900 Subject: [PATCH 2/2] fix attribute type filter --- src/aiodynamo/expressions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aiodynamo/expressions.py b/src/aiodynamo/expressions.py index 305d799..7fa6f9e 100644 --- a/src/aiodynamo/expressions.py +++ b/src/aiodynamo/expressions.py @@ -446,7 +446,7 @@ class AttributeTypeCondition(Condition): attribute_type: AttributeType def encode(self, params: Parameters) -> str: - return f"attribute_type({params.encode_path(self.field.path)}, {self.attribute_type.value})" + return f"attribute_type({params.encode_path(self.field.path)}, {params.encode_value(self.attribute_type.value)})" @dataclass(frozen=True)