`SoftwareCatalogApi.upsert_catalog_entity` produces an unexpected error when passing a string argument as the body
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
Research direction
Start by reading src/datadog_api_client/v2/api/software_catalog_api.py at SoftwareCatalogApi.upsert_catalog_entity, then run the reproduction script from the issue with the JSON string body. Trace how that argument is serialized before the API request; done means a valid JSON or YAML entity string is accepted without the reported 400 error while the existing dictionary case continues to work.
Written by the indexing model from the issue text.
Description
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
- Dominant language
- Python
- Stars
- 166
- Forks
- 55
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 73
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from DataDog/datadog-api-client-python
-
stale
Difficulty 1/5 1-3 hours Newbie friendliness 72/100
DataDog/datadog-api-client-python#3535 · 1 comment ·
-
kind/bug stale
Difficulty 3/5 1-2 days Newbie friendliness 66/100
DataDog/datadog-api-client-python#3717 · 3 comments ·
-
kind/bug stale
Difficulty 3/5 1-2 days Newbie friendliness 75/100
DataDog/datadog-api-client-python#3656 · 1 comment ·
-
kind/bug stale
Difficulty 3/5 1-2 days Newbie friendliness 38/100
DataDog/datadog-api-client-python#3120 · 1 comment ·
-
stale
Difficulty 3/5 1-2 days Newbie friendliness 45/100
DataDog/datadog-api-client-python#2986 · 1 comment ·
All issues in DataDog/datadog-api-client-python
Similar issues
-
essnmx good first issue
Difficulty 1/5 Under an hour Newbie friendliness 95/100
-
[Feature] 奇物选择添加优先级 Open
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
syfoud/Simulated_Scepter#174 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Giskard-AI/giskard-oss#2840 · 1 comment ·
-
A claim comment carrying the issue number is silently declined while the workflow reports success Openarea: repo bug perceived difficulty: 2
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
yeti-platform/yeti#1380 ·