Skip to content

TypeError: unsupported operand type(s) for +=: 'NoneType' and 'str' during client initialization (v0.16.2) #85

@disenchant

Description

@disenchant

Description:
Since the release of version 0.16.2 (and currently on master), importing the V2 Client crashes with a TypeError.

This occurs because the OpenAPI specification shipped with the package (openapi.json) now contains request body properties that define an enum but do not provide a description.

When the dynamic API client generator parses these properties, it attempts to append the enum choices to a None description, causing the crash during the module import phase.

Steps to Reproduce:
Simply importing the client in an environment with exoscale==0.16.2 triggers the error:

from exoscale.api.v2 import Client

Stack Trace:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.14/site-packages/exoscale/api/v2.py", line 97, in <module>
    BaseClient = create_client_class(api_spec)
  File "/usr/local/lib/python3.14/site-packages/exoscale/api/generator.py", line 354, in create_client_class
    op_fn = _create_operation_call(
        py_operation_name,
        operation_name,
        operation,
        api_spec,
    )
  File "/usr/local/lib/python3.14/site-packages/exoscale/api/generator.py", line 243, in _create_operation_call
    desc += f". Must be one of ``{choices}``"
TypeError: unsupported operand type(s) for +=: 'NoneType' and 'str'

Root Cause & Location:
The bug is located in exoscale/api/generator.py inside the _create_operation_call function (around line 242):

        for name, prop in properties.items():
            # ...
            desc = prop.get("description") # <-- Returns None if missing
            if "enum" in item:
                choices = "``, ``".join(map(repr, item["enum"]))
                desc += f". Must be one of ``{choices}``" # <-- Crashes: None += str

Proposed Fix:
Ensure desc is initialized as an empty string if it is missing from the spec.

In exoscale/api/generator.py:

-           desc = prop.get("description")
+           desc = prop.get("description") or ""
            if "enum" in item:

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