Skip to content

[BUG][Python] Structured YAML bodies are not serialized #24083

Description

@tamird

Description

The synchronous Python client's RESTClientObject only serializes a
structured request body when Content-Type contains json. A dict or
list sent as application/yaml or with a +yaml structured suffix
instead reaches the fallback and raises ApiException with "Cannot
prepare a request message".

JSON serialization is valid YAML 1.2:
https://yaml.org/spec/1.2.2/#13-relation-to-json

This breaks Kubernetes server-side apply, whose dynamic client accepts
structured bodies and sends application/apply-patch+yaml. The
Kubernetes client has carried a downstream special case since
kubernetes-client/python@5529ded.

Expected behavior

Serialize structured bodies for YAML media types as JSON, while still
passing already serialized str and bytes bodies through unchanged.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions