Skip to content

fix(resources): accept legacy target field for uploads#1659

Open
xychendave wants to merge 1 commit intovolcengine:mainfrom
xychendave:fix/accept-legacy-target-field
Open

fix(resources): accept legacy target field for uploads#1659
xychendave wants to merge 1 commit intovolcengine:mainfrom
xychendave:fix/accept-legacy-target-field

Conversation

@xychendave
Copy link
Copy Markdown

Description

Add backward compatibility for legacy console upload payloads by accepting the deprecated target field in AddResourceRequest and mapping it to to.

This prevents older deployed console bundles from failing during the second step of the upload flow.

Related Issue

  • No linked issue

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test update

Changes Made

  • accept legacy target as a deprecated alias for to in AddResourceRequest
  • preserve existing behavior by letting explicit to continue to take precedence
  • add a regression test covering the legacy upload payload path

Testing

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have tested this on the following platforms:
    • Linux
    • macOS
    • Windows

Runtime validation performed in this environment:

  • reproduced the issue against a running 0.3.9 deployment where temp_upload succeeded and POST /api/v1/resources failed with 422
  • applied the compatibility fix locally and verified the same upload flow completed successfully

Note: the focused pytest run was not executed here because pytest was not installed in the available virtualenv.

Checklist

  • My code follows the project's coding style
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Additional Notes

The root cause was a drift between older published console bundles and the current server request schema:

  • legacy console payload: target
  • server request schema: to / parent

Because the request model forbids unknown fields, the upload flow failed before request handling logic could normalize the input.

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


tgg_ai_studio seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 23, 2026

PR Reviewer Guide 🔍

(Review updated until commit 1228f29)

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪
🏅 Score: 95
🧪 PR contains tests
🔒 No security concerns identified
✅ No TODO sections
🔀 No multiple PR themes
⚡ Recommended focus areas for review

Suggestion

Mark the target field as deprecated using Pydantic's Field(deprecated=True) to make the deprecation explicit in the model schema and documentation.

target: Optional[str] = None

@github-actions
Copy link
Copy Markdown

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Improve legacy alias handling

Mark the target field as deprecated using Pydantic's deprecated=True. Add validation
to reject conflicting to and target values, and include a deprecation warning when
target is used. Also ensure the model state is consistent after alias application.

openviking/server/routers/resources.py [73-98]

-target: Optional[str] = None
+target: Optional[str] = Field(None, deprecated=True, description="Deprecated legacy alias for 'to'.")
 parent: Optional[str] = None
 reason: str = ""
 instruction: str = ""
 wait: bool = False
 timeout: Optional[float] = None
 strict: bool = False
 source_name: Optional[str] = None
 ignore_dirs: Optional[str] = None
 include: Optional[str] = None
 exclude: Optional[str] = None
 directly_upload_media: bool = True
 preserve_structure: Optional[bool] = None
 telemetry: TelemetryRequest = False
 watch_interval: float = 0
 
 @model_validator(mode="before")
 @classmethod
 def apply_legacy_target_alias(cls, data):
     if not isinstance(data, dict):
         return data
-
-    if not data.get("to") and data.get("target"):
-        data = dict(data)
+    data = dict(data)
+    has_to = "to" in data and data["to"] is not None
+    has_target = "target" in data and data["target"] is not None
+    if has_to and has_target and data["to"] != data["target"]:
+        raise ValueError("Cannot provide both conflicting 'to' and 'target' fields. Use only 'to'.")
+    if has_target and not has_to:
         data["to"] = data["target"]
     return data
Suggestion importance[1-10]: 7

__

Why: The suggestion improves robustness by adding validation to reject conflicting to and target values, properly marks target as deprecated using Pydantic's deprecated=True, and maintains consistent model state after alias application.

Medium

@xychendave xychendave marked this pull request as ready for review May 6, 2026 06:50
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

Persistent review updated to latest commit 1228f29

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

PR Code Suggestions ✨

No code suggestions found for the PR.

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

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants