Skip to content

Commit b243bbe

Browse files
committed
Problem: Filtering by start_date or end_date would fail assertion
Solution: Allow floats to be included in HTTP params
1 parent 00592c2 commit b243bbe

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/aleph/sdk/query/filters.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,15 @@ def as_http_params(self) -> Dict[str, str]:
8383
"endDate": _date_field_to_float(self.end_date),
8484
}
8585

86-
# Ensure all values are strings.
87-
result: Dict[str, str] = {}
86+
# Ensure all values are strings or float
87+
result: Dict[str, Union[str, float]] = {}
8888

8989
# Drop empty values
9090
for key, value in partial_result.items():
9191
if value:
92-
assert isinstance(value, str), f"Value must be a string: `{value}`"
92+
assert isinstance(value, str) or isinstance(
93+
value, float
94+
), f"Value must be a string or float: `{value}`"
9395
result[key] = value
9496

9597
return result
@@ -150,13 +152,15 @@ def as_http_params(self) -> Dict[str, str]:
150152
"endDate": _date_field_to_float(self.end_date),
151153
}
152154

153-
# Ensure all values are strings.
154-
result: Dict[str, str] = {}
155+
# Ensure all values are strings or float
156+
result: Dict[str, Union[str, float]] = {}
155157

156158
# Drop empty values
157159
for key, value in partial_result.items():
158160
if value:
159-
assert isinstance(value, str), f"Value must be a string: `{value}`"
161+
assert isinstance(value, str) or isinstance(
162+
value, float
163+
), f"Value must be a string or float: `{value}`"
160164
result[key] = value
161165

162166
return result

tests/unit/test_asynchronous_get.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import unittest
2+
from datetime import datetime
23
from typing import Any, Dict
34
from unittest.mock import AsyncMock
45

@@ -75,6 +76,7 @@ async def test_get_posts():
7576
page_size=2,
7677
post_filter=PostFilter(
7778
channels=["TEST"],
79+
start_date=datetime(2021, 1, 1),
7880
),
7981
)
8082

@@ -89,6 +91,7 @@ async def test_get_messages():
8991
page_size=2,
9092
message_filter=MessageFilter(
9193
message_types=[MessageType.post],
94+
start_date=datetime(2021, 1, 1),
9295
),
9396
)
9497

0 commit comments

Comments
 (0)