From 6971a24388840a75c8df1e1913569b2454342097 Mon Sep 17 00:00:00 2001 From: Herman Snevajs Date: Mon, 22 Sep 2025 14:24:24 +0200 Subject: [PATCH 1/2] Return OLD server only for 404 resp --- mergin/client.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/mergin/client.py b/mergin/client.py index ec6d155..0cb9648 100644 --- a/mergin/client.py +++ b/mergin/client.py @@ -380,14 +380,18 @@ def server_type(self): try: resp = self.get("/config", validate_auth=False) config = json.load(resp) - if config["server_type"] == "ce": + stype = config.get("server_type") + if stype == "ce": self._server_type = ServerType.CE - elif config["server_type"] == "ee": + elif stype == "ee": self._server_type = ServerType.EE - elif config["server_type"] == "saas": + elif stype == "saas": self._server_type = ServerType.SAAS - except (ClientError, KeyError): - self._server_type = ServerType.OLD + except ClientError as e: + if getattr(e, "status_code", None) == 404: + self._server_type = ServerType.OLD + else: + raise return self._server_type From 59e04fe0da977a7942f8688cb60d85f2f9f9868a Mon Sep 17 00:00:00 2001 From: Herman Snevajs Date: Wed, 24 Sep 2025 12:15:19 +0200 Subject: [PATCH 2/2] Fix 'http_error' & add test --- mergin/client.py | 2 +- mergin/test/test_client.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/mergin/client.py b/mergin/client.py index 0cb9648..101c62e 100644 --- a/mergin/client.py +++ b/mergin/client.py @@ -388,7 +388,7 @@ def server_type(self): elif stype == "saas": self._server_type = ServerType.SAAS except ClientError as e: - if getattr(e, "status_code", None) == 404: + if getattr(e, "http_error", None) == 404: self._server_type = ServerType.OLD else: raise diff --git a/mergin/test/test_client.py b/mergin/test/test_client.py index 58278b5..07cdeec 100644 --- a/mergin/test/test_client.py +++ b/mergin/test/test_client.py @@ -11,6 +11,8 @@ import sqlite3 import glob +from unittest.mock import patch, Mock + from .. import InvalidProject from ..client import ( MerginClient, @@ -3008,3 +3010,19 @@ def test_validate_auth(mc: MerginClient): # this should pass and not raise an error, as the client is able to re-login with pytest.raises(LoginError): mc_auth_token_login_wrong_password.validate_auth() + + +def test_server_type(mc): + """Test mc.server_type() method""" + # success + assert mc.server_type() == ServerType.SAAS + mc._server_type = None + with patch("mergin.client.MerginClient.get") as mock_client_get: + # 404 + mock_client_get.side_effect = ClientError(detail="Not found", http_error=404) + assert mc.server_type() == ServerType.OLD + mc._server_type = None + # 503 + mock_client_get.side_effect = ClientError(detail="Service unavailable", http_error=503) + with pytest.raises(ClientError, match="Service unavailable"): + mc.server_type()