Skip to content

Commit 1162962

Browse files
authored
fix(client): replace server_version property with get_server_version() method (#83)
The async client exposed get_server_version() as a method; the sync client exposed server_version as a property, hiding the I/O cost. This inconsistency made the API misleading — property access should not trigger a network call. Changes: - Add get_server_version() to ConfigClient (same logic as the old property) - Deprecate the server_version property with DeprecationWarning pointing to get_server_version() - Update check_compatibility() to call get_server_version() directly - Update test suite: rename cached-fetch test, add deprecation-warning test Co-Authored-By: Claude <noreply@anthropic.com> Closes #52
1 parent 337a2d6 commit 1162962

2 files changed

Lines changed: 35 additions & 9 deletions

File tree

sdk/src/opendecree/client.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
from __future__ import annotations
1313

14+
import warnings
1415
from datetime import timedelta
1516
from typing import TYPE_CHECKING, overload
1617

@@ -108,9 +109,8 @@ def __enter__(self) -> ConfigClient:
108109
def __exit__(self, *exc: object) -> None:
109110
self.close()
110111

111-
@property
112-
def server_version(self) -> ServerVersion:
113-
"""The server's version, fetched once and cached.
112+
def get_server_version(self) -> ServerVersion:
113+
"""Fetch the server's version, cached after first call.
114114
115115
Returns:
116116
ServerVersion with version and commit strings.
@@ -124,6 +124,16 @@ def server_version(self) -> ServerVersion:
124124
)
125125
return self._server_version
126126

127+
@property
128+
def server_version(self) -> ServerVersion:
129+
"""Deprecated. Use :meth:`get_server_version` instead."""
130+
warnings.warn(
131+
"server_version property is deprecated; use get_server_version() instead.",
132+
DeprecationWarning,
133+
stacklevel=2,
134+
)
135+
return self.get_server_version()
136+
127137
def check_compatibility(self) -> None:
128138
"""Check that the server version is compatible with this SDK.
129139
@@ -135,7 +145,7 @@ def check_compatibility(self) -> None:
135145
supported range.
136146
UnavailableError: If the server is unreachable.
137147
"""
138-
check_version_compatible(self.server_version.version)
148+
check_version_compatible(self.get_server_version().version)
139149

140150
# --- get() with @overload for type safety ---
141151

sdk/tests/test_compat.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ async def test_async_fetch_server_version():
126126
assert sv == ServerVersion(version="0.3.1", commit="abc123")
127127

128128

129-
# --- ConfigClient.server_version + check_compatibility ---
129+
# --- ConfigClient.get_server_version + check_compatibility ---
130130

131131

132-
def test_client_server_version_cached():
133-
"""server_version property fetches once, returns cached."""
132+
def test_client_get_server_version_cached():
133+
"""get_server_version() fetches once, returns cached."""
134134
with patch("opendecree.client.create_channel"):
135135
from opendecree import ConfigClient
136136

@@ -147,16 +147,32 @@ def test_client_server_version_cached():
147147
client._server_version = None
148148

149149
# First call fetches
150-
v1 = client.server_version
150+
v1 = client.get_server_version()
151151
assert v1.version == "0.3.1"
152152
assert mock_stub.GetServerInfo.call_count == 1
153153

154154
# Second call returns cached
155-
v2 = client.server_version
155+
v2 = client.get_server_version()
156156
assert v2 is v1
157157
assert mock_stub.GetServerInfo.call_count == 1
158158

159159

160+
def test_client_server_version_property_deprecated():
161+
"""server_version property emits DeprecationWarning."""
162+
with patch("opendecree.client.create_channel"):
163+
from opendecree import ConfigClient
164+
165+
client = ConfigClient.__new__(ConfigClient)
166+
client._timeout = 5.0
167+
client._server_version = ServerVersion(version="0.3.1", commit="abc")
168+
client._version_stub = MagicMock()
169+
client._version_pb2 = MagicMock()
170+
171+
with pytest.warns(DeprecationWarning, match="get_server_version"):
172+
sv = client.server_version
173+
assert sv.version == "0.3.1"
174+
175+
160176
def test_client_check_compatibility_passes():
161177
with patch("opendecree.client.create_channel"):
162178
from opendecree import ConfigClient

0 commit comments

Comments
 (0)