`SoftwareCatalogApi.upsert_catalog_entity` produces an unexpected error when passing a string argument as the body
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 45/100
Direzione di ricerca
Inizia leggendo src/datadog_api_client/v2/api/software_catalog_api.py in corrispondenza di SoftwareCatalogApi.upsert_catalog_entity, quindi esegui lo script di riproduzione dell’issue con la stringa JSON come body. Traccia come viene serializzato quell’argomento prima della richiesta API; il lavoro è completato quando una stringa di entità JSON o YAML valida viene accettata senza l’errore 400 riportato e il caso esistente con un dizionario continua a funzionare.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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:
- 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)
- observe that the response is a
400and 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
- Lingua principale
- Python
- Stelle
- 166
- Fork
- 55
- Merge medio
- 2g 17h
- PR unite (30g)
- 73
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di DataDog/datadog-api-client-python
-
stale
Difficoltà 1/5 1-3 ore Idoneità per principianti 72/100
DataDog/datadog-api-client-python#3535 · 1 commento ·
-
kind/bug stale
Difficoltà 3/5 1-2 giorni Idoneità per principianti 66/100
DataDog/datadog-api-client-python#3717 · 3 commenti ·
-
kind/bug stale
Difficoltà 3/5 1-2 giorni Idoneità per principianti 75/100
DataDog/datadog-api-client-python#3656 · 1 commento ·
-
kind/bug stale
Difficoltà 3/5 1-2 giorni Idoneità per principianti 38/100
DataDog/datadog-api-client-python#3120 · 1 commento ·
-
stale
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
DataDog/datadog-api-client-python#2986 · 1 commento ·
Tutte le issue di DataDog/datadog-api-client-python
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
anthropics/skills#1811 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
speaches-ai/speaches#678 ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
datalayer/mcp-compose#42 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
conda-forge/spacy-feedstock#177 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
UKGovernmentBEIS/inspect_evals#2523 ·