Skip to content

fix(sdk): safely handle cases where volume.host is unset - #1659

Open
wlmvp wants to merge 2 commits into
opensandbox-group:mainfrom
wlmvp:fix-pythonsdk-volume-error
Open

fix(sdk): safely handle cases where volume.host is unset#1659
wlmvp wants to merge 2 commits into
opensandbox-group:mainfrom
wlmvp:fix-pythonsdk-volume-error

Conversation

@wlmvp

@wlmvp wlmvp commented Aug 27, 2026

Copy link
Copy Markdown

Summary

  • What is changing and why?

#1658

Testing

  • Not run (explain why)
  • Unit tests
  • Integration tests
  • e2e / manual verification

Breaking Changes

  • None
  • Yes (describe impact and migration path)

Checklist

  • Linked Issue or clearly described motivation
  • Added/updated docs (if needed)
  • Added/updated tests (if needed)
  • Security impact considered
  • Backward compatibility considered

@github-actions github-actions Bot added sdk/python size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Aug 27, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 31a4705a96

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines 130 to 131
if not isinstance(volume.host, Unset):
api_host = ApiHost(path=volume.host.path)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep checking optional volume fields for None

When a valid PVC or OSSFS volume is converted, the domain model sets volume.host to None; because None is not an instance of the generated Unset class, this branch executes and accessing .path raises AttributeError. Host volumes similarly fail at the repeated PVC or OSSFS guards, so every sandbox creation containing a volume now fails before sending its request. Retain the None checks (or explicitly accept both representations) and add a request-mapping regression test.

AGENTS.md reference: sdks/AGENTS.md:L119-L120

Useful? React with 👍 / 👎.

@wlmvp
wlmvp force-pushed the fix-pythonsdk-volume-error branch from 31a4705 to 16ee117 Compare August 28, 2026 01:33
@github-actions github-actions Bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Aug 28, 2026
@wlmvp
wlmvp force-pushed the fix-pythonsdk-volume-error branch from 16ee117 to 7508844 Compare August 28, 2026 01:44

@Pangjiping Pangjiping left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Blocking issues found, verified locally by parsing the changed file and running ruff:

  1. Syntax error at the sub_path guard (if misspelled as f) — the module cannot even be imported (SyntaxError: invalid syntax).
  2. No regression test for #1658, and no local verification was run (ruff/pytest would have caught the syntax error).
  3. Root-cause concern: for the documented domain Volume model the fields default to None, never Unset, so the new guards only fire for the generated API Volume type — please clarify the repro and cover it with a test.

Please also run uv run ruff check and uv run pytest on the Python SDK.


api_sub_path = UNSET
if volume.sub_path is not None:
f volume.sub_path is not None and not isinstance(volume.sub_path, Unset):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Syntax error: if is misspelled as f. The module cannot be parsed at all (SyntaxError: invalid syntax), so the Python SDK is unimportable — verified locally with ast.parse and uv run ruff check. Please fix and run uv run ruff check and uv run pytest (the PR currently only ran the auto-label CI check).


api_host = UNSET
if volume.host is not None:
if volume.host is not None and not isinstance(volume.host, Unset):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Missing regression test (the repo's SDK guidelines require one for every bug fix, and the PR checklist marks testing as "Not run"). There is no test reproducing #1658 ('Unset' object has no attribute 'path'). Please add a converter test covering to_api_volume with (a) an unset backend and (b) each backend set, then run uv run pytest.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Hi @Pangjiping, thanks for the review! I have addressed all your comments in the latest commit. All local tests (uv run pytest) and linting (uv run ruff check) pass successfully now. Could you please take another look? Thanks!


api_pvc = UNSET
if volume.pvc is not None:
if volume.pvc is not None and not isinstance(volume.pvc, Unset):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Concern about the root cause: the domain Volume model (opensandbox.models.sandboxes.Volume, the type shown in docs/examples) defaults host/pvc/ossfs/sub_path to None, not Unset — pydantic would reject an actual Unset value. So isinstance(volume.host, Unset) can only ever be true when callers pass the generated API Volume (opensandbox.api.lifecycle.models.Volume, whose fields default to UNSET) into create(). If that is the reported scenario, please state it in the PR and consider validating the input type (raise TypeError, as to_api_create_sandbox_request does for network_policy) instead of silently skipping, and add a repro test documenting the accepted input. Minor: new ossfs block has trailing whitespace (ruff W291).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Image

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

已补充test,当我创建携带pvc volumes的sandbox时,没有Unset判断就会报错,加上Unset判断后成功。

@wlmvp
wlmvp force-pushed the fix-pythonsdk-volume-error branch from 7508844 to 3b9064f Compare September 2, 2026 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sdk/python size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants