From c32bf92aa2ada4d57b4a2035b7752640bc214f66 Mon Sep 17 00:00:00 2001 From: Lino Giger <68745352+LinoGiger@users.noreply.github.com> Date: Mon, 13 Apr 2026 11:10:33 +0200 Subject: [PATCH] made optional api calls log to debug instead of error --- .../api/rapidata_api_client.py | 20 +++++++++++++++++++ .../rapidata_client/rapidata_client.py | 9 +++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/rapidata/rapidata_client/api/rapidata_api_client.py b/src/rapidata/rapidata_client/api/rapidata_api_client.py index 697f3793f..ac138b39b 100644 --- a/src/rapidata/rapidata_client/api/rapidata_api_client.py +++ b/src/rapidata/rapidata_client/api/rapidata_api_client.py @@ -36,6 +36,26 @@ def _should_suppress_error_logging() -> bool: return getattr(_thread_local, "suppress_error_logging", False) +@contextmanager +def optional_api_call(description: str): + """Mark a block as non-critical / best-effort. + + Inside the block: + - RapidataApiClient errors are logged at DEBUG instead of ERROR + (via suppress_rapidata_error_logging). + - Any exception that escapes the block is caught and logged at + DEBUG as well. The caller never sees it. + + Use for best-effort calls like version checks, telemetry, or + feature-flag lookups where failure must not impact the user. + """ + with suppress_rapidata_error_logging(): + try: + yield + except Exception as e: + logger.debug("Optional call '%s' failed: %s", description, e) + + class RapidataApiClient(ApiClient): """Custom API client that wraps errors in RapidataError.""" diff --git a/src/rapidata/rapidata_client/rapidata_client.py b/src/rapidata/rapidata_client/rapidata_client.py index aab43b0ac..290ca95a1 100644 --- a/src/rapidata/rapidata_client/rapidata_client.py +++ b/src/rapidata/rapidata_client/rapidata_client.py @@ -30,6 +30,7 @@ from rapidata.rapidata_client.datapoints._asset_uploader import AssetUploader from rapidata.rapidata_client.job.rapidata_job_manager import RapidataJobManager from rapidata.rapidata_client.flow.rapidata_flow_manager import RapidataFlowManager +from rapidata.rapidata_client.api.rapidata_api_client import optional_api_call class RapidataClient: @@ -130,7 +131,7 @@ def clear_all_caches(self): def _check_beta_features(self): """Enable beta features for the client.""" - try: + with optional_api_call("check beta features"): with tracer.start_as_current_span("RapidataClient.check_beta_features"): result: dict[str, Any] = json.loads( self._openapi_service.api_client.call_api( @@ -154,11 +155,9 @@ def _check_beta_features(self): logger.debug("User is an admin, enabling beta features") rapidata_config.enableBetaFeatures = True - except Exception as e: - logger.debug("Failed to check beta features: %s", e) def _check_version(self): - try: + with optional_api_call("version check"): response = requests.get( "https://api.github.com/repos/RapidataAI/rapidata-python-sdk/releases/latest", headers={"Accept": "application/vnd.github.v3+json"}, @@ -175,8 +174,6 @@ def _check_version(self): logger.debug( "Current version is up to date. Version: %s", __version__ ) - except Exception as e: - logger.debug("Failed to check for updates: %s", e) def __str__(self) -> str: return f"RapidataClient(environment={self._openapi_service.environment})"