Skip to content

Array of item /w enum creates invalid dataclass in python #6350

@ShawnSack

Description

@ShawnSack

What are you generating using Kiota, clients or plugins?

API Client/SDK

In what context or format are you using Kiota?

Linux executable

Client library/SDK language

Python

Describe the bug

I am trying to generate a library for https://developer.sophos.com/docs/endpoint-v1/1/overview
What I'm finding is that the generated python is creating invalid dataclasses for query parameters that include enums. For example in the api yaml:

        - in: query
          name: healthStatus
          description: Find endpoints by health status.
          style: form
          explode: false
          required: false
          schema:
            type: array
            items:
              type: string
              enum:
                - bad
                - good
                - suspicious
                - unknown

Creates a parameter in dataclass:

        # Find endpoints by health status.
        health_status: list[GetHealthStatusQueryParameterType] = []

Which causes the error:

Exception has occurred: ValueError
mutable default <class 'list'> for field health_status is not allowed: use default_factory

I don't really see a way to fix this without editing the generated code. I'm assuming it should be wrapped with Optional[] since it's an optional value.

Expected behavior

I should be able to run a get() without running into the "Exception has occurred: ValueError
mutable default <class 'list'> for field health_status is not allowed: use default_factory" Error.

How to reproduce

Generate for python using the attached yaml.
See endpoints/endpoints_request_builder.py

Open API description file

openapi-yaml-client-generated.zip

Kiota Version

1.24.1

Latest Kiota version known to work for scenario above?(Not required)

No response

Known Workarounds

No response

Configuration

  • OS: MacOS
  • Arm64

Debug output

Click to expand log ```
</details>


### Other information

_No response_

Metadata

Metadata

Assignees

Labels

Pythonhelp wantedIssue caused by core project dependency modules or librarystatus:waiting-for-author-feedbackIssue that we've responded but needs author feedback to closetype:bugA broken experience

Type

Projects

Status

Done ✔️

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions