diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e10faa..013fee0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Subscribing to new records, [PR-70](https://github.com/reductstore/reduct-py/pull/70) +### Fixed: + +- No int timestamps in queries, [PR-73](https://github.com/reductstore/reduct-py/pull/73) + ## [1.3.1] - 2023-01-30 ### Fixed: diff --git a/reduct/bucket.py b/reduct/bucket.py index ea7c808..d6f3c57 100644 --- a/reduct/bucket.py +++ b/reduct/bucket.py @@ -106,7 +106,7 @@ class Record: size: int """size of data""" last: bool - """last record in the query""" + """last record in the query. Deprecated: doesn't work for some cases""" content_type: str """content type of data""" read_all: Callable[[None], Awaitable[bytes]] @@ -215,7 +215,7 @@ async def read( >>> async with bucket.read("entry", timestamp=123456789) as record: >>> data = await record.read_all() """ - params = {"ts": timestamp} if timestamp else None + params = {"ts": int(timestamp)} if timestamp else None async with self._http.request( "GET", f"/b/{self.name}/{entry_name}", params=params ) as resp: @@ -256,7 +256,8 @@ async def write( >>> await bucket.write("entry-1", sender(), content_length=15) """ - params = {"ts": timestamp if timestamp else time.time_ns() / 1000} + timestamp = timestamp if timestamp else time.time_ns() / 1000 + params = {"ts": int(timestamp)} await self._http.request_all( "POST", f"/b/{self.name}/{entry_name}", @@ -353,11 +354,11 @@ async def subscribe( async def _query(self, entry_name, start, stop, ttl, **kwargs): params = {} if start: - params["start"] = start + params["start"] = int(start) if stop: - params["stop"] = stop + params["stop"] = int(stop) if ttl: - params["ttl"] = ttl + params["ttl"] = int(ttl) if "include" in kwargs: for name, value in kwargs["include"].items(): diff --git a/reduct/http.py b/reduct/http.py index 6b8aa0e..a2f8f91 100644 --- a/reduct/http.py +++ b/reduct/http.py @@ -53,7 +53,6 @@ async def request( headers=dict(self.headers, **extra_headers), **kwargs, ) as response: - if response.ok: yield response else: diff --git a/tests/bucket_test.py b/tests/bucket_test.py index ce6235d..73336c5 100644 --- a/tests/bucket_test.py +++ b/tests/bucket_test.py @@ -117,6 +117,7 @@ async def test__write_by_timestamp(bucket_2): async def test__write_with_current_time(bucket_2): """Should write a record with current time""" belated_timestamp = int(time.time_ns() / 1000) + await asyncio.sleep(0.01) await bucket_2.write("entry-3", b"test-data") await bucket_2.write("entry-3", b"old-data", timestamp=belated_timestamp) @@ -174,12 +175,10 @@ async def test_query_records(bucket_1): assert records[0].timestamp == 3000000 assert records[0].size == 11 assert records[0].content_type == "application/octet-stream" - assert not records[0].last assert records[1].timestamp == 4000000 assert records[1].size == 11 assert records[1].content_type == "application/octet-stream" - assert records[1].last @pytest.mark.asyncio @@ -212,7 +211,6 @@ async def test_query_records_included_labels(bucket_1): assert len(records) == 1 assert records[0].labels == {"label1": "value1", "label2": "value2"} - assert records[0].last @pytest.mark.asyncio @@ -233,7 +231,6 @@ async def test_query_records_excluded_labels(bucket_2): assert len(records) == 1 assert records[0].labels == {"label1": "value1", "label2": "value3"} - assert records[0].last @pytest.mark.asyncio diff --git a/tests/client_test.py b/tests/client_test.py index 9279d93..61560b3 100644 --- a/tests/client_test.py +++ b/tests/client_test.py @@ -48,7 +48,7 @@ async def test__bad_url_server_exists(): with pytest.raises(ReductError) as reduct_err: await client.info() - assert str(reduct_err.value) == ("Status 404: Not Found") + assert str(reduct_err.value) == ("Status 404: Not found") @pytest.mark.asyncio