Skip to content

fix: fallback to legacy API for private dataset/model info#3

Merged
wangxingjun778 merged 1 commit into
mainfrom
fix/v3_reviews
Jun 4, 2026
Merged

fix: fallback to legacy API for private dataset/model info#3
wangxingjun778 merged 1 commit into
mainfrom
fix/v3_reviews

Conversation

@wangxingjun778
Copy link
Copy Markdown
Member

The OpenAPI GET /datasets/{owner}/{name} endpoint returns 404 for private datasets even with a valid Bearer token. The legacy API with cookie-based session auth handles private repos correctly. Add a fallback: on NotExistError from OpenAPI, retry via the legacy client.

The OpenAPI GET /datasets/{owner}/{name} endpoint returns 404 for
private datasets even with a valid Bearer token. The legacy API with
cookie-based session auth handles private repos correctly. Add a
fallback: on NotExistError from OpenAPI, retry via the legacy client.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@wangxingjun778 wangxingjun778 merged commit 04f1737 into main Jun 4, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a fallback mechanism when retrieving repository metadata. Specifically, it adds a get_repo_info method to the legacy API that utilizes cookie-based session auth to support private repositories. In the main API, calls to fetch models or datasets via the OpenAPI client now catch NotExistError and fall back to this legacy endpoint. The reviewer suggested refactoring the duplicate try-except blocks for models and datasets into a single block to reduce code duplication.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/modelscope_hub/api.py
Comment on lines 645 to +654
if rt is RepoType.MODEL:
data = self.openapi.get_model(owner, name)
try:
data = self.openapi.get_model(owner, name)
except NotExistError:
data = self.legacy.get_repo_info(repo_id, str(rt))
elif rt is RepoType.DATASET:
data = self.openapi.get_dataset(owner, name)
try:
data = self.openapi.get_dataset(owner, name)
except NotExistError:
data = self.legacy.get_repo_info(repo_id, str(rt))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The try-except blocks for RepoType.MODEL and RepoType.DATASET are identical except for the specific OpenAPI method called. We can simplify this and reduce code duplication by grouping them together.

Suggested change
if rt is RepoType.MODEL:
data = self.openapi.get_model(owner, name)
try:
data = self.openapi.get_model(owner, name)
except NotExistError:
data = self.legacy.get_repo_info(repo_id, str(rt))
elif rt is RepoType.DATASET:
data = self.openapi.get_dataset(owner, name)
try:
data = self.openapi.get_dataset(owner, name)
except NotExistError:
data = self.legacy.get_repo_info(repo_id, str(rt))
if rt in (RepoType.MODEL, RepoType.DATASET):
try:
data = (
self.openapi.get_model(owner, name)
if rt is RepoType.MODEL
else self.openapi.get_dataset(owner, name)
)
except NotExistError:
data = self.legacy.get_repo_info(repo_id, str(rt))

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant