From 226e5532d8fa55b8b689d13b926082f910d3f096 Mon Sep 17 00:00:00 2001 From: Stef Pletinck Date: Thu, 10 Apr 2025 14:43:29 +0200 Subject: [PATCH 1/3] Fix: Obelisk TimestampPrecision as string When passing a TimestampPrecision object into the params, the full name of the enum gets encoded into TimestampPrecision.MILLISECONDS e.g. Obelisk understandably throws a fit and desires no prefixes. We missed a `.value` call, added back here. --- src/obelisk/asynchronous/producer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/obelisk/asynchronous/producer.py b/src/obelisk/asynchronous/producer.py index b0ad4f9..697b217 100644 --- a/src/obelisk/asynchronous/producer.py +++ b/src/obelisk/asynchronous/producer.py @@ -41,7 +41,7 @@ async def send(self, dataset: str, data: List[dict], params = { 'datasetId': dataset, - 'timestampPrecision': precision, + 'timestampPrecision': precision.value, 'mode': mode.value } From 4c6ffb8672ee3b3b683621f00f8da20753495be5 Mon Sep 17 00:00:00 2001 From: Stef Pletinck Date: Mon, 2 Jun 2025 09:52:33 +0200 Subject: [PATCH 2/3] Fix infinite loop in retry logic As described in the related issue. Fixes #10 --- src/obelisk/asynchronous/client.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/obelisk/asynchronous/client.py b/src/obelisk/asynchronous/client.py index 96f71b3..a0d7aa3 100644 --- a/src/obelisk/asynchronous/client.py +++ b/src/obelisk/asynchronous/client.py @@ -5,7 +5,7 @@ import httpx -from obelisk.exceptions import AuthenticationError +from obelisk.exceptions import AuthenticationError, ObeliskError from obelisk.strategies.retry import RetryStrategy, \ NoRetryStrategy from obelisk.types import ObeliskKind @@ -76,9 +76,10 @@ async def _get_token(self): async with httpx.AsyncClient() as client: response = None + request = None last_error = None retry = self.retry_strategy.make() - while not response or await retry.should_retry(): + while not response: try: request = await client.post( self._token_url, @@ -90,10 +91,13 @@ async def _get_token(self): except Exception as e: last_error = e self.log.error(e) - continue + if await retry.should_retry(): + continue + else: + break - if response is None and last_error is not None: - raise last_error + if not response or not request: + raise (last_error if last_error is not None else ObeliskError("No response")) if request.status_code != 200: if 'error' in response: @@ -142,7 +146,7 @@ async def http_post(self, url: str, data: Any = None, response = None retry = self.retry_strategy.make() last_error = None - while not response or await retry.should_retry(): + while not response: if response is not None: self.log.debug(f"Retrying, last response: {response.status_code}") @@ -158,7 +162,10 @@ async def http_post(self, url: str, data: Any = None, except Exception as e: self.log.error(e) last_error = e - continue + if await retry.should_retry(): + continue + else: + break if not response and last_error: raise last_error From bb777136b2698f48306a705e990bad8a7dff5a05 Mon Sep 17 00:00:00 2001 From: Stef Pletinck Date: Mon, 2 Jun 2025 09:55:24 +0200 Subject: [PATCH 3/3] Fix test secrets --- src/obelisk/asynchronous/consumer_test.py | 5 ++++- src/obelisk/sync/consumer_test.py | 11 +++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/obelisk/asynchronous/consumer_test.py b/src/obelisk/asynchronous/consumer_test.py index 7bd04f2..7348792 100644 --- a/src/obelisk/asynchronous/consumer_test.py +++ b/src/obelisk/asynchronous/consumer_test.py @@ -3,9 +3,12 @@ pytest_plugins = ('pytest_asyncio',) +client_id = "682c6c46604b3b3be35429df" +client_secret = "7136832d-01be-456a-a1fe-25c7f9e130c5" + @pytest.mark.asyncio async def test_demo_igent(): - consumer = Consumer(client="67c716e616c11421cfe2faf6", secret="08dafe89-0389-45b4-9832-cc565fb8c2eb") + consumer = Consumer(client=client_id, secret=client_secret) result = await consumer.single_chunk( datasets=["612f6c39cbceda0ea9753d95"], metrics=["org.dyamand.types.common.Temperature::number"], diff --git a/src/obelisk/sync/consumer_test.py b/src/obelisk/sync/consumer_test.py index ca6d308..f053cfb 100644 --- a/src/obelisk/sync/consumer_test.py +++ b/src/obelisk/sync/consumer_test.py @@ -1,7 +1,10 @@ from .consumer import Consumer +client_id = "682c6c46604b3b3be35429df" +client_secret = "7136832d-01be-456a-a1fe-25c7f9e130c5" + def test_demo_igent(): - consumer = Consumer(client="67c716e616c11421cfe2faf6", secret="08dafe89-0389-45b4-9832-cc565fb8c2eb") + consumer = Consumer(client=client_id,secret=client_secret) result = consumer.single_chunk( datasets=["612f6c39cbceda0ea9753d95"], metrics=["org.dyamand.types.common.Temperature::number"], @@ -13,8 +16,8 @@ def test_demo_igent(): assert len(result.items) == 2 def test_two_instances(): - consumer_one = Consumer(client="67c716e616c11421cfe2faf6", secret="08dafe89-0389-45b4-9832-cc565fb8c2eb") - consumer_two = Consumer(client="67c716e616c11421cfe2faf6", secret="08dafe89-0389-45b4-9832-cc565fb8c2eb") + consumer_one = Consumer(client=client_id,secret=client_secret) + consumer_two = Consumer(client=client_id,secret=client_secret) result_one = consumer_one.single_chunk( datasets=["612f6c39cbceda0ea9753d95"], metrics=["org.dyamand.types.common.Temperature::number"], @@ -22,7 +25,7 @@ def test_two_instances(): to_timestamp=1741100614258, limit=2 ) - result_two = consumer_one.single_chunk( + result_two = consumer_two.single_chunk( datasets=["612f6c39cbceda0ea9753d95"], metrics=["org.dyamand.types.common.Temperature::number"], from_timestamp=1740924034000,