Skip to content

**Bug:** TypeError: 'NoneType' object is not iterable in CreateSandboxResponse.from_dict when running main_use_pool.py #589

@zson-two

Description

@zson-two

Describe the bug

When attempting to run the official project example examples/code-interpreter/main_use_pool.py via the Python SDK, if the backend API returns a response where the metadata field is explicitly null (parsed as None in Python), the SDK throws a TypeError. This causes the entire Sandbox.create() call to fail during the parsing phase.

To Reproduce

Run the provided example:

python examples/code-interpreter/main_use_pool.py

(Or similarly using uv run if inside a project setup).

If the API payload for the 202 Accepted response includes "metadata": null, the client will crash with the following exception:

Error stack trace

Traceback (most recent call last):
  File "/Users/.../main_use_pool.py", line 114, in <module>
    asyncio.run(main())
  File ".../site-packages/opensandbox/sandbox.py", line 460, in create
    response = await sandbox_service.create_sandbox(...)
  File ".../site-packages/opensandbox/adapters/sandboxes_adapter.py", line 142, in create_sandbox
    response_obj = await post_sandboxes.asyncio_detailed(...)
  File ".../site-packages/opensandbox/api/lifecycle/api/sandboxes/post_sandboxes.py", line 204, in asyncio_detailed
    return _build_response(client=client, response=response)
  File ".../site-packages/opensandbox/api/lifecycle/api/sandboxes/post_sandboxes.py", line 90, in _build_response
    parsed=_parse_response(client=client, response=response),
  File ".../site-packages/opensandbox/api/lifecycle/api/sandboxes/post_sandboxes.py", line 53, in _parse_response
    response_202 = CreateSandboxResponse.from_dict(response.json())
  File ".../site-packages/opensandbox/api/lifecycle/models/create_sandbox_response.py", line 112, in from_dict
    metadata = CreateSandboxResponseMetadata.from_dict(_metadata)
  File ".../site-packages/opensandbox/api/lifecycle/models/create_sandbox_response_metadata.py", line 42, in from_dict
    d = dict(src_dict)
TypeError: 'NoneType' object is not iterable

Root Cause

In the auto-generated client model opensandbox/api/lifecycle/models/create_sandbox_response.py, the from_dict method pops "metadata" and checks if it is Unset:

        _metadata = d.pop("metadata", UNSET)
        metadata: CreateSandboxResponseMetadata | Unset
        if isinstance(_metadata, Unset):
            metadata = UNSET
        else:
            # Here _metadata can be None, causing the failure inside from_dict
            metadata = CreateSandboxResponseMetadata.from_dict(_metadata)

Because _metadata parses as None, isinstance(_metadata, Unset) evaluates to False. The code then erroneously passes None to CreateSandboxResponseMetadata.from_dict(), which blindly attempts to execute d = dict(src_dict) where src_dict is None.

Proposed Solution

Update create_sandbox_response.py (and any identically typed auto-generated models) to properly check for None:

        _metadata = d.pop("metadata", UNSET)
        metadata: CreateSandboxResponseMetadata | Unset
        if isinstance(_metadata, Unset) or _metadata is None:
            metadata = UNSET
        else:
            metadata = CreateSandboxResponseMetadata.from_dict(_metadata)

Alternatively, standardizing the model annotation so that metadata natively expects | None would fully resolve the bug on the schema side.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions