Skip to content

Commit f6cbc3d

Browse files
committed
Stop suppressing warnings around the session constructor
warnings.catch_warnings swaps the module-global filter list, not a thread-local one, so the window silently dropped every other thread's DeprecationWarning for the duration of the construction. Keeping it cost more than the duplicate warning it hid, and the two warnings are not redundant: one names the factory the caller used, the other the class it keeps using afterwards. Without it the method body is main's again, and warnings is no longer imported. Signed-off-by: Honglin Cao <hocao@nvidia.com>
1 parent 30f4fab commit f6cbc3d

2 files changed

Lines changed: 7 additions & 9 deletions

File tree

‎centml/sdk/api.py‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import time
2-
import warnings
32
from bisect import insort
43
from contextlib import contextmanager
54
from dataclasses import dataclass
@@ -502,11 +501,7 @@ def deployment_log_session(
502501
Stateful reader for one pod's logs that tracks fetched pages and anchors
503502
every request itself — see DeploymentLogSession. Seed events with logs a
504503
previous session (or get_deployment_logs) returned for the same pod."""
505-
with warnings.catch_warnings():
506-
# This call already warned via its own decorator; constructing the
507-
# (also-deprecated) session class must not warn a second time.
508-
warnings.simplefilter("ignore", DeprecationWarning)
509-
return DeploymentLogSession(self, deployment_id, revision_number, pod, events)
504+
return DeploymentLogSession(self, deployment_id, revision_number, pod, events)
510505

511506

512507
@deprecated("DeploymentLogSession is deprecated; use CentMLClient.fetch_logs() instead")

‎tests/test_sdk_api.py‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,9 +1051,12 @@ def test_deprecated_log_readers_warn_and_name_the_replacement():
10511051
client.get_deployment_logs_range(123, 2)
10521052
with pytest.warns(DeprecationWarning, match="fetch_logs") as caught:
10531053
session = client.deployment_log_session(123, 2, "pod-a")
1054-
# Exactly one warning: the method's own, not a second from constructing the
1055-
# (also-deprecated) session class inside it.
1056-
assert len(caught) == 1
1054+
# Two warnings, one per deprecated surface the call crosses: the factory the
1055+
# caller named, and the session class it hands back for the caller to keep using.
1056+
assert [str(warning.message) for warning in caught] == [
1057+
"deployment_log_session() is deprecated; use fetch_logs() instead",
1058+
"DeploymentLogSession is deprecated; use CentMLClient.fetch_logs() instead",
1059+
]
10571060
with pytest.warns(DeprecationWarning, match="fetch_logs"):
10581061
DeploymentLogSession(client, 123, 2, "pod-a")
10591062

0 commit comments

Comments
 (0)