dynatrace-oss / api-client-python

Dynatrace API Python client
Apache License 2.0
60 stars 22 forks source link

"None is not a valid Unit" in metrics.list.query(fields="entityType") #90

Open vduseev opened 2 months ago

vduseev commented 2 months ago

Describe the bug If there is not unit field in the raw reply from the https://{your-environment-id}.live.dynatrace.com/api/v2/metrics API, the client doesn't handle it properly.

https://github.com/dynatrace-oss/api-client-python/blob/620213cf7bfff5e214bb4c20e1bbd0a31cac41d4/dynatrace/environment_v2/metrics.py#L230

The Unit enum doesn't have any value for None, obviously.

To Reproduce Steps to reproduce the behavior:

Solution:

Most likely, this needs to be rewritten to

self.unit: Optional[Unit] = Unit(raw_element.get("unit")) if raw_element.get("unit") else None

Currently, you can go around that by specifying unit as a field:

client.metrics.list.query(page_size=500, fields="+entityType,+unit")