HealthITAU / pyconnectwise

A library for simplifying interactions with the ConnectWise Manage API in Python
https://healthit.com.au
GNU General Public License v3.0
42 stars 7 forks source link

Configurations with custom fields cause pydantic to choke #25

Open s2unified opened 4 months ago

s2unified commented 4 months ago

Hi,

When calling my configuration list for domain names it has custom fields in, and this seems to cause pydantic to choke.

Calling configuration = cwm.company.configurations.paginated(1,1000).params={'conditions': 'type/id=55'}

Traceback (most recent call last):
  File "domain-expiry-refresh.py", line 38, in <module>
    configuration = cwm.company.configurations.paginated(1,1000).params={'conditions': 'type/id=55'}
  File "C:\Program Files (x86)\Python311-32\Lib\site-packages\pyconnectwise\endpoints\manage\CompanyConfigurationsEndpoint.py", line 91, in paginated
    return PaginatedResponse(
  File "C:\Program Files (x86)\Python311-32\Lib\site-packages\pyconnectwise\responses\paginated_response.py", line 55, in __init__
    self._initialize(response, response_model, endpoint, page, page_size, params)
  File "C:\Program Files (x86)\Python311-32\Lib\site-packages\pyconnectwise\responses\paginated_response.py", line 101, in _initialize
    self.data: list[TModel] = [
  File "C:\Program Files (x86)\Python311-32\Lib\site-packages\pyconnectwise\responses\paginated_response.py", line 102, in <listcomp>
    response_model.model_validate(d) for d in response.json()
  File "C:\Program Files (x86)\Python311-32\Lib\site-packages\pydantic\main.py", line 509, in model_validate
    return cls.__pydantic_validator__.validate_python(
pydantic_core._pydantic_core.ValidationError: 2 validation errors for CompanyConfiguration
questions.0.answer
  Input should be a valid dictionary [type=dict_type, input_value='configuration_custom_secret_value_1', input_type=str]
    For further information visit https://errors.pydantic.dev/2.6/v/dict_type
questions.1.answer
  Input should be a valid dictionary [type=dict_type, input_value='configuration_custom_secret_value_2, input_type=str]
    For further information visit https://errors.pydantic.dev/2.6/v/dict_type

Hoping this isn't something too weird! I have removed the actual values that were returned as they were confidential and replaced it with configuration_custom_secret_value

aescolastico commented 2 hours ago

yes, there are several endpoints that simply do not function due to valid bodies or resource paths getting rejected by the pydantic models. which i presume are generated based on connectwise' api spec. which frankly is unreliable based on my personal experience with those api docs. unfortunately, the maintainer doesnt seem to be active on this repo anymore.