Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

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

Aberta
#2,438 5 comentários 1 reação 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 2 dias

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
3/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
45/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Estagnada
Stack de tecnologia
python
Domínio
api

Direção de pesquisa

Comece lendo src/datadog_api_client/v2/api/software_catalog_api.py em SoftwareCatalogApi.upsert_catalog_entity e, em seguida, execute o script de reprodução da issue com a string JSON no body. Rastreie como esse argumento é serializado antes da requisição à API; considera-se concluído quando uma string de entidade JSON ou YAML válida é aceita sem o erro 400 relatado, enquanto o caso existente com um dicionário continua funcionando.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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

Linguagem predominante
Python
Estrelas
167
Forks
55
Merge médio
2d 23h
PRs com merge (30d)
74

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de DataDog/datadog-api-client-python

Todas as issues de DataDog/datadog-api-client-python

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.