yanyongyu / githubkit

The modern, all-batteries-included GitHub SDK for Python, including rest api, graphql, webhooks, like octokit!
https://yanyongyu.github.io/githubkit/
MIT License
177 stars 25 forks source link

TypeError: unhashable type: 'list' with pydantic version <2.5.2 #58

Closed mattibo closed 10 months ago

mattibo commented 10 months ago

when i run this code i get an TypeError after i upgraded to pydantic version 2.5:

from githubkit import GitHub

with GitHub() as github:
    resp = github.rest.repos.get(owner="yanyongyu", repo="githubkit")
    repo = resp.parsed_data

following error is raised:

Traceback (most recent call last):
  File "githubkit\test.py", line 5, in <module>
    repo = resp.parsed_data
           ^^^^^^^^^^^^^^^^
  File "githubkit\githubkit\response.py", line 50, in parsed_data
    return TypeAdapter(self._data_model).validate_json(self.content)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "githubkit\venv\Lib\site-packages\pydantic\type_adapter.py", line 256, in validate_json
    return self.validator.validate_json(__data, strict=strict, context=context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: unhashable type: 'list'

maybe this has something todo with the new json parsing library pydantic hast introduced with version 2.5: https://docs.pydantic.dev/2.5/concepts/json/#json-parsing

yanyongyu commented 10 months ago

it seems the following code also reports the same error:

try to use validate_python to avoid pydantic json parsing

TypeAdapter(resp._data_model).validate_python(resp.json())

Is this a bug of pydantic?

mattibo commented 10 months ago

The bug is fixed with version 2.5.2 of pydantic: https://github.com/pydantic/pydantic/releases/tag/v2.5.2

Maybe ignore the version 2.5.0 and 2.5.1 in pyproject.toml of githubkit?