From c1478cd8f3df4e8f221451be346aaef2976fbe76 Mon Sep 17 00:00:00 2001 From: Bernard Gawor Date: Wed, 28 Jan 2026 13:18:09 +0100 Subject: [PATCH 1/2] show deprecation warnings --- fishjam/api/_client.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/fishjam/api/_client.py b/fishjam/api/_client.py index c73fc61..6763c51 100644 --- a/fishjam/api/_client.py +++ b/fishjam/api/_client.py @@ -1,3 +1,5 @@ +import json +import warnings from typing import cast from fishjam._openapi_client.client import AuthenticatedClient @@ -16,12 +18,33 @@ def __init__(self, fishjam_id: str, management_token: str): token=management_token, headers={"x-fishjam-api-client": f"python-server/{get_version()}"}, ) + self.warnings_shown = False def _request(self, method, **kwargs): response = method.sync_detailed(client=self.client, **kwargs) + self._handle_deprecation_header(response.headers) if isinstance(response.parsed, Error): response = cast(Response[Error], response) raise HTTPError.from_response(response) return response.parsed + + def _handle_deprecation_header(self, headers): + deprecation_warning = headers.get("x-fishjam-api-deprecated") + if deprecation_warning and not self.warnings_shown: + self.warnings_shown = True + deprecation_warning = json.loads(deprecation_warning) + + status = deprecation_warning["status"] + msg = deprecation_warning["message"] + + match status: + case "unsupported": + warnings.warn(message=msg, category=UserWarning, stacklevel=4) + case "deprecated": + warnings.warn( + message=msg, category=DeprecationWarning, stacklevel=4 + ) + case _: + pass From ca50504b5615f66ef5d9a9a80a863654070884da Mon Sep 17 00:00:00 2001 From: Bernard Gawor Date: Wed, 28 Jan 2026 13:48:38 +0100 Subject: [PATCH 2/2] apply copilot suggestion --- fishjam/api/_client.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/fishjam/api/_client.py b/fishjam/api/_client.py index 6763c51..4a30e7a 100644 --- a/fishjam/api/_client.py +++ b/fishjam/api/_client.py @@ -34,10 +34,16 @@ def _handle_deprecation_header(self, headers): deprecation_warning = headers.get("x-fishjam-api-deprecated") if deprecation_warning and not self.warnings_shown: self.warnings_shown = True - deprecation_warning = json.loads(deprecation_warning) + try: + deprecation_data = json.loads(deprecation_warning) + except (json.JSONDecodeError, TypeError, ValueError): + return - status = deprecation_warning["status"] - msg = deprecation_warning["message"] + status = deprecation_data["status"] + msg = deprecation_data["message"] + + if not status or not msg: + return match status: case "unsupported":