Synqly / python-sdk

Python SDK for accessing Synqly APIs
Apache License 2.0
3 stars 0 forks source link

Members client - list method not working due to pydantic error #34

Open hh2110 opened 1 week ago

hh2110 commented 1 week ago

Hi, a call to response = management_client.members.list() results in

---------------------------------------------------------------------------
ValidationError                           Traceback (most recent call last)
Cell In[12], [line 1]
----> [1] response = management_client.members.list()

File ~/synqly/management/resources/members/client.py:102, in MembersClient.list(self, limit, start_after, order, filter, request_options)
     [69](site-packages/synqly/management/resources/members/client.py:69) _response = self._client_wrapper.httpx_client.request(
     [70](site-packages/synqly/management/resources/members/client.py:70)     "GET",
     [71](site-packages/synqly/management/resources/members/client.py:71)     urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "v1/members"),
   (...)
     [99](site-packages/synqly/management/resources/members/client.py:99)     max_retries=request_options.get("max_retries") if request_options is not None else 0,  # type: ignore
    [100](site-packages/synqly/management/resources/members/client.py:100) )
    [101](site-packages/synqly/management/resources/members/client.py:101) if 200 <= _response.status_code < 300:
--> [102](site-packages/synqly/management/resources/members/client.py:102)     return pydantic.parse_obj_as(ListMembersResponse, _response.json())  # type: ignore
    [103](site-packages/synqly/management/resources/members/client.py:103) if _response.status_code == 400:
    [104](site-packages/synqly/management/resources/members/client.py:104)     raise BadRequestError(pydantic.parse_obj_as(ErrorBody, _response.json()))  # type: ignore

File ~/pydantic/v1/tools.py:38, in parse_obj_as(type_, obj, type_name)
     [36](site-packages/pydantic/v1/tools.py:36) def parse_obj_as(type_: Type[T], obj: Any, *, type_name: Optional[NameFactory] = None) -> T:
     [37](site-packages/pydantic/v1/tools.py:37)     model_type = _get_parsing_type(type_, type_name=type_name)  # type: ignore[arg-type]
---> [38](site-packages/pydantic/v1/tools.py:38)     return model_type(__root__=obj).__root__

File ~/pydantic/v1/main.py:341, in BaseModel.__init__(__pydantic_self__, **data)
    [339](site-packages/pydantic/v1/main.py:339) values, fields_set, validation_error = validate_model(__pydantic_self__.__class__, data)
    [340](site-packages/pydantic/v1/main.py:340) if validation_error:
--> [341](site-packages/pydantic/v1/main.py:341)     raise validation_error
    [342](site-packages/pydantic/v1/main.py:342) try:
    [343](site-packages/pydantic/v1/main.py:343)     object_setattr(__pydantic_self__, '__dict__', values)

ValidationError: 4 validation errors for ParsingModel[ListMembersResponse]
__root__ -> result -> 0 -> nickname
  field required (type=value_error.missing)
__root__ -> result -> 0 -> picture
  field required (type=value_error.missing)
__root__ -> result -> 1 -> nickname
  field required (type=value_error.missing)
__root__ -> result -> 1 -> picture
  field required (type=value_error.missing)

I think the pydantic model that has the nickname and picture attributes should have them as optional attributes

arcurtis commented 1 week ago

Thanks for filing this @hh2110

I attempted to reproduce with a minimal project; however, when using the latest version of the SDK, I don't see this validation error. Digging deeper, it appears this was fixed in SDK version 0.3.12.

Here is the code where these are now marked as optional with a default value of None. That is here: https://github.com/Synqly/python-sdk/blob/main/src/synqly/management/resources/member_base/types/member.py#L31

What SDK version are you using? is it possible to upgrade to 0.3.12 or later?