Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions nominal/core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand All @@ -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,
)
Comment thread
seanmreidy marked this conversation as resolved.
Comment thread
seanmreidy marked this conversation as resolved.
trust_store_path = certifi.where() if trust_store_path is None else trust_store_path
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing Test Coverage: This warning functionality needs comprehensive tests to ensure it works correctly. Consider adding tests using pytest.warns() to verify:

  1. Warning is emitted when workspace_rid=None
  2. No warning when workspace_rid is provided
  3. Warning message and category are correct
  4. Stacklevel correctly points to user code

The warning should also be tested for the create() and from_profile() code paths mentioned in the PR description.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a bit excessive for just a warning message

timeout_seconds = connect_timeout.total_seconds() if isinstance(connect_timeout, timedelta) else connect_timeout
cfg = ServiceConfiguration(
Comment thread
seanmreidy marked this conversation as resolved.
Expand Down
1 change: 1 addition & 0 deletions nominal/experimental/impersonation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
2 changes: 1 addition & 1 deletion tests/core/test_clientsbunch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
)

Expand Down
6 changes: 4 additions & 2 deletions tests/e2e/test_workspace_resolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
(
Expand Down
Loading