From a10aeeed821e684bce7236464fd88731773ed157 Mon Sep 17 00:00:00 2001 From: jsonbailey Date: Wed, 24 Jun 2026 10:11:10 -0500 Subject: [PATCH] fix: Correct data source error reporting Two pre-existing bugs in the sync data-source error reporting, independent of the async work: - datasource/polling.py: pass time.time() (not the uncalled time.time) so the UNKNOWN-error DataSourceErrorInfo records a real timestamp. - datasourcev2/polling.py: use response.status in the HTTP-error message instead of interpolating the urllib3 response object. Also retargets the stale version-gated-upsert TODO in datasource/status.py to SDK-62 (the proper fix needs a breaking upsert -> bool change, deferred to the next major version). SDK-2592 --- ldclient/impl/datasource/polling.py | 2 +- ldclient/impl/datasource/status.py | 4 ++-- ldclient/impl/datasourcev2/polling.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ldclient/impl/datasource/polling.py b/ldclient/impl/datasource/polling.py index d6c22dc8..3392594c 100644 --- a/ldclient/impl/datasource/polling.py +++ b/ldclient/impl/datasource/polling.py @@ -99,4 +99,4 @@ def _poll(self): log.exception('Error: Exception encountered when updating flags. %s' % e) if self._data_source_update_sink is not None: - self._data_source_update_sink.update_status(DataSourceState.INTERRUPTED, DataSourceErrorInfo(DataSourceErrorKind.UNKNOWN, 0, time.time, str(e))) + self._data_source_update_sink.update_status(DataSourceState.INTERRUPTED, DataSourceErrorInfo(DataSourceErrorKind.UNKNOWN, 0, time.time(), str(e))) diff --git a/ldclient/impl/datasource/status.py b/ldclient/impl/datasource/status.py index c9813e04..f59fd49c 100644 --- a/ldclient/impl/datasource/status.py +++ b/ldclient/impl/datasource/status.py @@ -55,8 +55,8 @@ def init_store(): def upsert(self, kind: VersionedDataKind, item: dict): self.__monitor_store_update(lambda: self.__store.upsert(kind, item)) - # TODO(sc-212471): We only want to do this if the store successfully - # updates the record. + # TODO(SDK-62): We only want to do this if the store successfully wrote the record, + # which requires upsert to return a bool result (breaking change). key = item.get('key', '') self.__update_dependency_for_single_item(kind, key, item) diff --git a/ldclient/impl/datasourcev2/polling.py b/ldclient/impl/datasourcev2/polling.py index 326a3e2b..c10b0fcd 100644 --- a/ldclient/impl/datasourcev2/polling.py +++ b/ldclient/impl/datasourcev2/polling.py @@ -303,7 +303,7 @@ def fetch(self, selector: Optional[Selector]) -> PollingResult: if response.status >= 400: return _Fail( - f"HTTP error {response}", UnsuccessfulResponseException(response.status), + f"HTTP error {response.status}", UnsuccessfulResponseException(response.status), headers=headers, ) @@ -531,7 +531,7 @@ def fetch(self, selector: Optional[Selector]) -> PollingResult: headers = response.headers if response.status >= 400: return _Fail( - f"HTTP error {response}", UnsuccessfulResponseException(response.status), + f"HTTP error {response.status}", UnsuccessfulResponseException(response.status), headers=headers )