Skip to content

Commit

Permalink
Merge pull request #175 from HENNGE/fix-attribute-type-filter
Browse files Browse the repository at this point in the history
Fix attribute type filter
  • Loading branch information
ojii authored Jan 19, 2024
2 parents bfc8db5 + 821255f commit 567e202
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/aiodynamo/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 13 additions & 1 deletion tests/integration/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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"}

0 comments on commit 567e202

Please sign in to comment.