Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

`SoftwareCatalogApi.upsert_catalog_entity` produces an unexpected error when passing a string argument as the body

Abierto
#2,438 5 comentarios 1 reacción 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
45/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
python
Área
api

Línea de trabajo

Empieza leyendo src/datadog_api_client/v2/api/software_catalog_api.py en SoftwareCatalogApi.upsert_catalog_entity y luego ejecuta el script de reproducción del issue con el string JSON como body. Rastrea cómo se serializa ese argumento antes de la solicitud a la API; se considera completado cuando se acepta un string de entidad JSON o YAML válido sin el error 400 indicado y el caso existente con un diccionario sigue funcionando.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

kind/bug stale

Describe the bug

The SoftwareCatalogApi.upsert_catalog_entity does not accept string arguments, despite its type annotation and the API documentation ("Entity definition in raw JSON or YAML representation") suggesting that it should accept a string.

To Reproduce
Steps to reproduce the behavior:

  1. Run this script:
import json
from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.software_catalog_api import SoftwareCatalogApi


payload: dict[str, Any] = {
    'apiVersion': 'v3',
    'kind': 'service',
    'metadata': {
        'name': 'my-service',
        'contacts': [],
        'displayName': 'my-service',
        'description': 'my service description',
        'links': [],
        'owner': 'my-team',
        'additionalOwners': [],
        'tags': [],
    },
    'spec': {
        'lifecycle': 'Stable',
        'tier': 'critical',
        'type': 'ecs-service',
    }
}


configuration = Configuration()


with APiClient(configuration) as api_client:
    catalog_api = SoftwareCatalogApi(api_client)
    response = catalog_api.upsert_catalog_entity(body=json.dumps(payload))
    print(response)
  1. observe that the response is a 400 and the response body contains an error:
{'errors': [{'title': 'Generic Error', 'detail': 'failed to parse entitties: failed preparsing step: error [yaml: unmarshal errors:\n  line 1: cannot unmarshal !!str `{"apiVe...` into entity.T] while parsing yaml: \n "[... contents omitted for brevity ...]"'}]}

To me, this appears to be because it is not parsing the string as a YAML document body, but rather, as a single string element.

If you simply remove json.dumps from the body argument and send the dictionary directly, the request is successful (despite this failing static type analyses like mypy):

-     response = catalog_api.upsert_catalog_entity(body=json.dumps(payload))
+     response = catalog_api.upsert_catalog_entity(body=payload)  # works, but fails type-checking

Expected behavior

That an error does not occur and that YAML (or JSON, being a subset of YAML) body as a string containing a valid entity description is accepted by the API.

Environment and Versions (please complete the following information):

Reproduced on Python3.12 with datadog-api-client version 2.32.0

Lenguaje dominante
Python
Estrellas
166
Forks
55
Merge medio
2 d 17 h
PR fusionados (30 d)
73

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de DataDog/datadog-api-client-python

Todos los issues de DataDog/datadog-api-client-python

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.