diff --git a/nominal/core/client.py b/nominal/core/client.py index fc494632..0303a832 100644 --- a/nominal/core/client.py +++ b/nominal/core/client.py @@ -3,6 +3,7 @@ import enum import logging import uuid +import warnings from dataclasses import dataclass, field from datetime import datetime, timedelta from io import TextIOBase @@ -171,6 +172,7 @@ def from_token( connect_timeout: timedelta | float = DEFAULT_CONNECT_TIMEOUT, extra_headers: HeaderProvider | Mapping[str, str] | None = None, _profile: str | None = None, + _workspace_warning_emitted: bool = False, ) -> Self: """Create a connection to the Nominal platform from a token. @@ -184,6 +186,13 @@ def from_token( connect_timeout: Request connection timeout. extra_headers: Extra request headers, either as a mapping or HeaderProvider. """ + if workspace_rid is None and not _workspace_warning_emitted: + warnings.warn( + "NominalClient will soon require a workspace RID. " + "Any client which doesn't have a workspace RID specified will fail.", + UserWarning, + stacklevel=2, + ) trust_store_path = certifi.where() if trust_store_path is None else trust_store_path timeout_seconds = connect_timeout.total_seconds() if isinstance(connect_timeout, timedelta) else connect_timeout cfg = ServiceConfiguration( diff --git a/nominal/experimental/impersonation/__init__.py b/nominal/experimental/impersonation/__init__.py index dd2c41a2..a0b66fe6 100644 --- a/nominal/experimental/impersonation/__init__.py +++ b/nominal/experimental/impersonation/__init__.py @@ -18,4 +18,5 @@ def as_user(client: NominalClient, user_rid: str) -> NominalClient: connect_timeout=client._clients._service_config.connect_timeout, extra_headers={ON_BEHALF_OF_USER_RID_HEADER: user_rid}, _profile=client._profile, + _workspace_warning_emitted=True, ) diff --git a/tests/core/test_clientsbunch.py b/tests/core/test_clientsbunch.py index bf24dc98..577811f9 100644 --- a/tests/core/test_clientsbunch.py +++ b/tests/core/test_clientsbunch.py @@ -222,7 +222,7 @@ def test_experimental_as_user_returns_derived_nominal_client(monkeypatch): "https://api.nominal.test", "test-agent", "token", - None, + "ri.workspace.main.workspace.test", ) ) diff --git a/tests/e2e/test_workspace_resolution.py b/tests/e2e/test_workspace_resolution.py index 377cfe89..2a418100 100644 --- a/tests/e2e/test_workspace_resolution.py +++ b/tests/e2e/test_workspace_resolution.py @@ -45,7 +45,8 @@ def test_workspace_rid_for_search_returns_none_for_all(client: NominalClient) -> def test_unconfigured_client_uses_workspace_service_default(client: NominalClient, pytestconfig) -> None: """Without a pinned workspace, DEFAULT should resolve to the tenant's service-side default.""" - unconfigured_client = _client_with_workspace_override(client, pytestconfig, workspace_rid=None) + with pytest.warns(UserWarning, match="NominalClient will soon require a workspace RID"): + unconfigured_client = _client_with_workspace_override(client, pytestconfig, workspace_rid=None) expected_workspace_rid = _get_service_default_workspace_rid(unconfigured_client) assert unconfigured_client._clients.resolve_default_workspace_rid() == expected_workspace_rid @@ -54,7 +55,8 @@ def test_unconfigured_client_uses_workspace_service_default(client: NominalClien def test_configured_workspace_rid_takes_precedence_over_service_default(client: NominalClient, pytestconfig) -> None: """A pinned workspace RID should win over the tenant default exposed by the workspace service.""" - unconfigured_client = _client_with_workspace_override(client, pytestconfig, workspace_rid=None) + with pytest.warns(UserWarning, match="NominalClient will soon require a workspace RID"): + unconfigured_client = _client_with_workspace_override(client, pytestconfig, workspace_rid=None) service_default_workspace_rid = _get_service_default_workspace_rid(unconfigured_client) configured_workspace = next( (