Skip to content

[issue-7393] [SDK] fix: use direct project-scoped URL for dataset in get_or_create_dataset log - #7440

Closed
Aftabbs wants to merge 1 commit into
comet-ml:mainfrom
Aftabbs:Aftabbs/issue-7393-fix-dataset-url-to-direct
Closed

[issue-7393] [SDK] fix: use direct project-scoped URL for dataset in get_or_create_dataset log#7440
Aftabbs wants to merge 1 commit into
comet-ml:mainfrom
Aftabbs:Aftabbs/issue-7393-fix-dataset-url-to-direct

Conversation

@Aftabbs

@Aftabbs Aftabbs commented Jul 12, 2026

Copy link
Copy Markdown

Details

get_dataset_url_by_id was generating a session-redirect URL
(v1/session/redirect/datasets/?dataset_id=...) that routes through
the user's session context and surfaces the dataset under "Default Project"
instead of the actual project it belongs to. This meant the URL logged by
create_dataset / get_or_create_dataset opened the wrong view in the UI.

The fix replaces the session-redirect URL with the same direct URL pattern
used by get_project_url_by_id:
{domain_root}opik/{workspace}/datasets/{dataset_id}/

The workspace is already available on the client as self._workspace.

Change checklist

  • User facing
  • Documentation update

Issues

AI-WATERMARK

AI-WATERMARK: yes

  • Tools: Claude Code
  • Model(s): claude-sonnet-4-6
  • Scope: url_helpers.py (function rewrite), opik_client.py (call site), test_url_helpers.py (new parametrized test)
  • Human verification: diff reviewed; test cases manually verified against the URL pattern used by get_project_url_by_id

Testing

Existing tests pass (no change to their expectations).

New test added: test_get_dataset_url_by_id__returns_direct_project_scoped_url
validates 4 parameter combinations (localhost + comet.com, with and without
trailing slash on the base URL).

Run with:

cd sdks/python
pytest tests/unit/test_url_helpers.py -v

Documentation

No documentation change required — this fixes a log message URL, not a
public API.

@github-actions github-actions Bot added python Pull requests that update Python code tests Including test files, or tests related like configuration. Python SDK 🟢 size/S labels Jul 12, 2026
Comment on lines +63 to +65
def get_dataset_url_by_id(dataset_id: str, base_url: str, workspace: str) -> str:
domain_root = get_base_url(base_url)
return f"{domain_root}opik/{workspace}/datasets/{dataset_id}/"

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.

get_dataset_url_by_id has two issues: get_base_url() strips the path prefix down to netloc, so subpath installs like https://example.com/custom/api/ produce host-root links that 404 behind reverse-proxy deployments; and workspace/dataset_id are interpolated raw, so values with /, spaces, or ? produce malformed URLs — should we derive the UI root the same way as get_ui_url() and URL-encode both path segments?

Severity

Want Baz to fix this for you? Activate Fixer

Other fix methods

Fix in Cursor

Prompt for AI Agents
Before applying, verify this suggestion against the current code. In
sdks/python/src/opik/url_helpers.py around lines 63-65, in
`get_dataset_url_by_id(dataset_id: str, base_url: str, workspace: str)`: 1. Stop using
`get_base_url(base_url)` because it drops path prefixes (everything after the domain).
Refactor to derive the UI root the same way as `get_ui_url()` and other UI URL helpers
(preserving any prefix before `/api`), then build the dataset path under that UI root so
it matches existing UI routing. 2. URL-quote `workspace` and `dataset_id` as individual
path segments (using the same allowed/safe character policy as the rest of the module)
before formatting them into the path, to prevent characters like `/`, spaces, or `?`
from producing malformed or misrouted links. Ensure the returned URL still ends with a
trailing slash and remains consistent with the module's existing quoting/encoding
approach.

Comment on lines 235 to +236
dataset_url = url_helpers.get_dataset_url_by_id(
dataset_id, self._config.url_override
dataset_id, self._config.url_override, self._workspace

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.

Default workspace leaks into dataset URL

self._workspace is passed straight into get_dataset_url_by_id(), but OpikConfig.workspace can still be the "default" sentinel or blank since get_from_user_inputs() only strips None, so cloud users can log .../opik/default/datasets/<id>/ or .../opik//datasets/<id>/ instead of the real workspace URL — should we reuse the get_project_url() dereference via self._rest_client.check.get_workspace_name().workspace_name here?

Severity

Want Baz to fix this for you? Activate Fixer

Other fix methods

Fix in Cursor

Prompt for AI Agents
Before applying, verify this suggestion against the current code. In
sdks/python/src/opik/api_objects/opik_client.py around lines 235-236 in the
_display_created_dataset_url method, don’t pass self._workspace verbatim into
url_helpers.get_dataset_url_by_id. Instead, reuse the same logic used by
get_project_url() to dereference the sentinel/default workspace to the actual workspace
slug via self._rest_client.check.get_workspace_name().workspace_name, and ensure
blank/empty workspace input is normalized so the URL path doesn’t contain double
slashes. Refactor to compute a single resolved workspace value once (e.g., a small
helper or local variable) and pass that resolved workspace into get_dataset_url_by_id
before logging the created dataset URL.

@Aftabbs

Aftabbs commented Jul 23, 2026

Copy link
Copy Markdown
Author

Closing — this was superseded by #7467 which landed a more complete fix (using project_id for the dataset URL and also covering test suites). The experiment URL fix is tracked in #7589.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

baz: pending Python SDK python Pull requests that update Python code 🟢 size/S tests Including test files, or tests related like configuration.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SDK: Fix dataset URL logged by get_or_create_dataset to use direct project-scoped URL

1 participant