`SoftwareCatalogApi.upsert_catalog_entity` produces an unexpected error when passing a string argument as the body
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
Thanks for your contribution!
This issue has been automatically marked as stale because it has not had activity in the last 30 days. Note that the issue will not be automatically closed, but this notification will remind us to investigate why there's been inactivity. Thank you for participating in the Datadog open source community.
If you would like this issue to remain open:
-
Verify that you can still reproduce the issue in the latest version of this project.
-
Comment that the issue is still reproducible and include updated details requested in the issue template.
https://docs.datadoghq.com/api/latest/software-catalog/?code-lang=python#create-or-update-entities
The docs currently recommend using a EntityV3Service object as the body argument. This also fails type checking for the upsert function.
Thanks for your contribution!
This issue has been automatically marked as stale because it has not had activity in the last 30 days. Note that the issue will not be automatically closed, but this notification will remind us to investigate why there's been inactivity. Thank you for participating in the Datadog open source community.
If you would like this issue to remain open:
-
Verify that you can still reproduce the issue in the latest version of this project.
-
Comment that the issue is still reproducible and include updated details requested in the issue template.
I'm no longer working with the company that had this issue, but there haven't been any code changes in the relevant source code responsible for the issue. So, I would conclude that the issue is still reproducible in the latest version of this project, with the same details as originally posted.
Thanks for your contribution!
This issue has been automatically marked as stale because it has not had activity in the last 30 days. Note that the issue will not be automatically closed, but this notification will remind us to investigate why there's been inactivity. Thank you for participating in the Datadog open source community.
If you would like this issue to remain open:
-
Verify that you can still reproduce the issue in the latest version of this project.
-
Comment that the issue is still reproducible and include updated details requested in the issue template.