[SDK] fix: use direct workspace-scoped URL for experiment link in evaluate() - #7463
Closed
Aftabbs wants to merge 1 commit into
Closed
[SDK] fix: use direct workspace-scoped URL for experiment link in evaluate()#7463Aftabbs wants to merge 1 commit into
Aftabbs wants to merge 1 commit into
Conversation
…luate() Replace the session-redirect URL in get_experiment_url_by_id() with a direct frontend URL, matching the approach used for get_project_url_by_id() and the dataset URL fix in comet-ml#7440. The new URL format is: {domain_root}opik/{workspace}/experiments/{dataset_id}/compare?experiments={json_encoded_ids} The JSON experiments array is URL-encoded to satisfy TanStack Router's JsonParam query parameter convention used on the CompareExperimentsPage. All 5 call sites in evaluator.py are updated to pass base_url and workspace (client._workspace) instead of url_override. Closes comet-ml#7462.
Comment on lines
31
to
+36
| def get_experiment_url_by_id( | ||
| dataset_id: str, experiment_id: str, url_override: str | ||
| dataset_id: str, experiment_id: str, base_url: str, workspace: str | ||
| ) -> str: | ||
| encoded_opik_url = base64.b64encode(url_override.encode("utf-8")).decode("utf-8") | ||
|
|
||
| project_path = urllib.parse.quote( | ||
| f"v1/session/redirect/experiments/?experiment_id={experiment_id}&dataset_id={dataset_id}&path={encoded_opik_url}", | ||
| safe=ALLOWED_URL_CHARACTERS, | ||
| ) | ||
| return urllib.parse.urljoin(ensure_ending_slash(url_override), project_path) | ||
| domain_root = get_base_url(base_url) | ||
| experiments_param = urllib.parse.quote(json.dumps([experiment_id])) | ||
| return f"{domain_root}opik/{workspace}/experiments/{dataset_id}/compare?experiments={experiments_param}" |
Contributor
There was a problem hiding this comment.
Broken compare-page links
get_experiment_url_by_id() emits /opik/{workspace}/experiments/{dataset_id}/compare without the /projects/{projectId} segment the compare route expects (per apps/opik-frontend/src/v2/router.tsx), so experiment_url stored in EvaluationResult doesn't resolve — should we add project_id back to the path, or reuse the previous redirect URL approach?
Want Baz to fix this for you? Activate Fixer
Other fix methods
Prompt for AI Agents
Before applying, verify this suggestion against the current code. In
sdks/python/src/opik/url_helpers.py around lines 31-36 in `get_experiment_url_by_id()`,
the returned URL no longer includes the required `/projects/{projectId}` path segment
and therefore won't resolve to the frontend compare page
(`apps/opik-frontend/src/v2/router.tsx` and `useDatasetIdFromCompareExperimentsURL.ts`).
Refactor the helper to generate a project-scoped compare/redirect URL again: either add
`project_id` to the function parameters and include it in the path before
`/experiments/{dataset_id}/compare`, or reuse the previous redirect URL approach so the
emitted `experiment_url` matches what the routed page expects. After updating the URL
construction, run/adjust any existing unit tests and add a small test/fixture that
asserts the produced URL contains the `/projects/` segment for external consumers.
Author
|
Closing in favour of a clean replacement PR based on the current main (which added get_base_url, get_dataset_url_by_id with project_id, and get_test_suite_url_by_id since this branch was opened). The new PR resolves the merge conflict and targets the same fix. |
Closed
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #7440 (which fixed
get_dataset_url_by_id). This PR fixesget_experiment_url_by_id()to use the same direct-URL pattern instead of the opaque session-redirect.Before:
After:
Changes
url_helpers.py: Changedget_experiment_url_by_id(dataset_id, experiment_id, url_override)toget_experiment_url_by_id(dataset_id, experiment_id, base_url, workspace). The direct URL mirrors the pattern inget_project_url_by_id()andget_dataset_url_by_id()(post-[issue-7393] [SDK] fix: use direct project-scoped URL for dataset in get_or_create_dataset log #7440). Theexperimentsquery param is URL-encoded JSON (%5B%22id%22%5D) to match TanStack Router'sJsonParamconvention on the Compare Experiments page.evaluator.py: Updated all 5 call sites to passbase_url=client.config.url_override, workspace=client._workspace.test_url_helpers.py: Added 3 parametrized cases covering localhost, trailing-slash variant, and cloud URL.Design decision
get_experiment_url_by_idnow acceptsworkspaceexplicitly (likeget_project_url_by_idandget_dataset_url_by_id). For users on the default OSS workspace,client._workspaceis"default", which is the correct path segment. For Comet cloud users,client._workspaceholds the actual workspace name. This matches existing conventions in the codebase.Test plan
pytest sdks/python/tests/unit/test_url_helpers.py -k test_get_experiment_url_by_id— all 3 new cases passevaluate()against a local opik instance; verify the printed URL opens directly in the browser without a redirect hopCloses #7462