-
Notifications
You must be signed in to change notification settings - Fork 0
rename sandbox fields #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,7 @@ | |
| SandboxStatusResponseDict, | ||
| TransformRuleDict, | ||
| ) | ||
| from .config import DEFAULT_MEMORY_MIB, DEFAULT_TEMPLATE_NAME, DEFAULT_TIMEOUT_MIN, DEFAULT_VCPU | ||
| from .config import DEFAULT_MEMORY_MIB, DEFAULT_TEMPLATE_NAME, DEFAULT_TIMEOUT, DEFAULT_VCPU | ||
|
|
||
| class SandboxState(str, Enum): | ||
| """Lifecycle states for a sandbox.""" | ||
|
|
@@ -110,8 +110,8 @@ class CreateSandboxParams(BaseModel): | |
|
|
||
| template_name: str = DEFAULT_TEMPLATE_NAME | ||
| vcpu: int = DEFAULT_VCPU | ||
| memory_mib: int = DEFAULT_MEMORY_MIB | ||
| timeout_min: int = DEFAULT_TIMEOUT_MIN | ||
| memory: int = DEFAULT_MEMORY_MIB | ||
| timeout: int = DEFAULT_TIMEOUT | ||
| auto_pause: bool = False | ||
| otel_export: bool = False | ||
| env_vars: dict[str, str] | None = None | ||
|
|
@@ -126,10 +126,10 @@ def _validate_values(self) -> CreateSandboxParams: | |
| raise ValueError("template_name must be at most 64 characters") | ||
| if not 1 <= self.vcpu <= 8: | ||
| raise ValueError("vcpu must be between 1 and 8") | ||
| if self.memory_mib < 512 or self.memory_mib > 8192 or self.memory_mib % 2 != 0: | ||
| raise ValueError("memory_mib must be an even number between 512 and 8192") | ||
| if not 1 <= self.timeout_min <= 480: | ||
| raise ValueError("timeout_min must be between 1 and 480") | ||
| if self.memory < 512 or self.memory > 8192 or self.memory % 2 != 0: | ||
| raise ValueError("memory must be an even number between 512 and 8192") | ||
| if not 1 <= self.timeout <= 28800: | ||
| raise ValueError("timeout must be between 1 and 28800") | ||
| self.network_policy = _validate_network_policy(self.network_policy) | ||
| self.template_name = template_name | ||
| return self | ||
|
|
@@ -172,8 +172,9 @@ class Sandbox(SandboxHandle): | |
| id: str | ||
| template_id: str = "" | ||
| vcpu: int = 0 | ||
| memory_mib: int = 0 | ||
| disk_mib: int = 0 | ||
| memory: int = 0 | ||
| disk: int = 0 | ||
| timeout: int = 0 | ||
| state: SandboxState | str = SandboxState.STARTING | ||
| auto_pause: bool = False | ||
| created_at: str = "" | ||
|
|
@@ -190,8 +191,9 @@ def from_dict(cls, data: SandboxCreateResponseDict) -> Sandbox: | |
| id=sandbox_id, | ||
| template_id=data.get("template_id", ""), | ||
| vcpu=int(data.get("vcpu", 0)), | ||
| memory_mib=int(data.get("memory_mib", 0)), | ||
| disk_mib=int(data.get("disk_mib", 0)), | ||
| memory=int(data.get("memory", 0)), | ||
| disk=int(data.get("disk", 0)), | ||
| timeout=int(data.get("timeout", 0)), | ||
|
Comment on lines
+194
to
+196
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't silently turn missing renamed fields into If the backend omits one of these keys—or still returns the legacy names during rollout—both parsers manufacture 💡 Minimal hard-fail / fallback shape- memory=int(data.get("memory", 0)),
- disk=int(data.get("disk", 0)),
- timeout=int(data.get("timeout", 0)),
+ memory=_require_int(data, "memory", legacy_key="memory_mib"),
+ disk=_require_int(data, "disk", legacy_key="disk_mib"),
+ timeout=_require_int(data, "timeout", legacy_key="timeout_min"),def _require_int(data: Mapping[str, object], key: str, *, legacy_key: str | None = None) -> int:
value = data.get(key)
if value is None and legacy_key is not None:
value = data.get(legacy_key)
if value is None:
raise ValueError(f"sandbox response missing required field {key!r}")
try:
return int(value)
except (TypeError, ValueError) as err:
raise ValueError(f"sandbox response has invalid {key!r}: {value!r}") from errAlso applies to: 227-229 🤖 Prompt for AI Agents |
||
| state=state, | ||
| auto_pause=bool(data.get("auto_pause", False)), | ||
| created_at=data.get("created_at", ""), | ||
|
|
@@ -204,8 +206,9 @@ class SandboxStatus(SandboxHandle): | |
| id: str | ||
| template_id: str | ||
| vcpu: int | ||
| memory_mib: int | ||
| disk_mib: int | ||
| memory: int | ||
| disk: int | ||
| timeout: int | ||
| state: SandboxState | str | ||
| auto_pause: bool | ||
| created_at: str | ||
|
|
@@ -221,8 +224,9 @@ def from_dict(cls, data: SandboxStatusResponseDict) -> SandboxStatus: | |
| id=sandbox_id, | ||
| template_id=data.get("template_id", ""), | ||
| vcpu=int(data.get("vcpu", 0)), | ||
| memory_mib=int(data.get("memory_mib", 0)), | ||
| disk_mib=int(data.get("disk_mib", 0)), | ||
| memory=int(data.get("memory", 0)), | ||
| disk=int(data.get("disk", 0)), | ||
| timeout=int(data.get("timeout", 0)), | ||
| state=state, | ||
| auto_pause=bool(data.get("auto_pause", False)), | ||
| created_at=data.get("created_at", ""), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
Consider a short compatibility window for the renamed public fields.
These names changed on public request/response models in-place, so downstream code still using
memory_mib,disk_mib, ortimeout_minwill break on upgrade. If this is not meant to be a hard breaking release, keep deprecated aliases/properties for one cycle and serialize only the new wire names.Also applies to: 175-177, 209-211