Closed angrykirc closed 10 months ago
Thank you for noting this. I'll review and reproduce.
I'm unable to reproduce this, using Python boolean notation when setting various boolean parameters I see the request succeed and looking at the request body I can see the proper json notation used:
slo = dt.slos.create(name="abc", target=98, warning=99, timeframe="-24h", use_rate_metric=False, enabled=False, metric_denominator="dsfm:billing.hostunit.assigned", metric_numerator="dsfm:billing.hostunit.assigned")
r = dt.slos.post(slo)
print(r.status_code)
print(r.request.body)
>201
>b'{"name": "abc", "target": 98, "warning": 99, "timeframe": "-24h", "evaluationType": "AGGREGATE", "enabled": false, "useRateMetric": false, "metricRate": "", "metricNumerator": "dsfm:billing.hostunit.assigned", "metricDenominator": "dsfm:billing.hostunit.assigned", "filter": null, "customDescription": null}'
And I can see the new SLO created in Dynatrace with the values I set.
If you can provide additional details to reproduce I can look again.
Actually, looking at another endpoint (list) not the one noted here I see the issue described. However, the issue is that this API wants a string in this field not a boolean value so it doesn't want true
it wants "true"
. I'm not sure why this API works this way, but regardless the issue seems to be on the API side and all we can do is likely change some of the typing on this field to show it should be a string for true or false rather than a boolean value at all.
I checked internally and there is a reason for the way this is how it is on the API side. I'll update the typing/defaults to make it clear this should be a string.
Describe the bug Dynatrace expects boolean fields in JSON notation (lowercase, true or false), yet they are sent to Dynatrace in Pythonic notation (True or False) when using slos.create method.
To Reproduce dt.slos.create(name="abc", target=98, warning=99, timeframe="-24h", use_rate_metric=False, enabled=True [...]) Dynatrace will throw a validation error on the enabled and useRateMetric fields.
Additional context There is a workaround for this bug - by replacing boolean values with lowercase strings (e.g. enabled="false"), they are not manually converted and so the request will succeed.