Skip to content
This repository has been archived by the owner on Dec 23, 2024. It is now read-only.

ValidationError when calling find_project_usage due to incorrect type validation #107

Open
marcosmamorim opened this issue Sep 9, 2024 · 0 comments

Comments

@marcosmamorim
Copy link

I’m encountering a ValidationError when using the equinix_metal Python SDK while trying to call the find_project_usage method. The error seems to occur because the price, quantity, and total fields are expected to be strings, but the API is returning them as floats.

Code to Reproduce:

import equinix_metal

def get_equinix_metal_client(api_token):
    conf = equinix_metal.Configuration(
        host="https://api.equinix.com/metal/v1"
    )
    conf.api_key['x_auth_token'] = api_token
    conf.debug = True
    return equinix_metal.ApiClient(conf)

api_token = 'API_TOKEN'
api_client = get_equinix_metal_client(api_token)

project_id = '1a4158ca-723e-459f-b963-4a0d7396XXXXX'

api_instance = equinix_metal.UsagesApi(api_client)
api_response = api_instance.find_project_usage(project_id)
print("API RESPONSE")
print(api_response)

Error Traceback:

Traceback (most recent call last):
  File "/path/to/project/test-equinix-metal.py", line 19, in <module>
    api_response = api_instance.find_project_usage(project_id)
  File "/path/to/project/.venv/lib/python3.11/site-packages/equinix_metal/api/usages_api.py", line 409, in find_project_usage
    return self.api_client.response_deserialize(
  File "/path/to/project/.venv/lib/python3.11/site-packages/equinix_metal/api_client.py", line 316, in response_deserialize
    return_data = self.deserialize(response_text, response_type)
  File "/path/to/project/.venv/lib/python3.11/site-packages/equinix_metal/api_client.py", line 392, in deserialize
    return self.__deserialize(data, response_type)
  File "/path/to/project/.venv/lib/python3.11/site-packages/equinix_metal/api_client.py", line 437, in __deserialize
    return self.__deserialize_model(data, klass)
  File "/path/to/project/.venv/lib/python3.11/site-packages/equinix_metal/api_client.py", line 759, in __deserialize_model
    return klass.from_dict(data)
  File "/path/to/project/.venv/lib/python3.11/site-packages/equinix_metal/models/project_usage_list.py", line 94, in from_dict
    "usages": [ProjectUsage.from_dict(_item) for _item in obj["usages"]] if obj.get("usages") is not None else None
  File "/path/to/project/.venv/lib/python3.11/site-packages/equinix_metal/models/project_usage.py", line 92, in from_dict
    _obj = cls.model_validate({
  File "/path/to/project/.venv/lib/python3.11/site-packages/pydantic/main.py", line 568, in model_validate
    return cls.__pydantic_validator__.validate_python(
pydantic_core._pydantic_core.ValidationError: 3 validation errors for ProjectUsage
price
  Input should be a valid string [type=string_type, input_value=2.45, input_type=float]
quantity
  Input should be a valid string [type=string_type, input_value=195.0, input_type=float]
total
  Input should be a valid string [type=string_type, input_value=477.75, input_type=float]
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant