thesadru / genshin.py

API wrapper for HoYoLAB/Miyoushe API built on asyncio and pydantic.
https://thesadru.github.io/genshin.py
MIT License
395 stars 72 forks source link

breaking Pydantic v2 behavior always raises error for root_validator #135

Closed JJonnick closed 1 year ago

JJonnick commented 1 year ago

I get the following error when executing a Github Action:

Run python3 ./codes.py
Traceback (most recent call last):
  File "/home/runner/work/genshinStats/genshinStats/./codes.py", line 5, in <module>
    import genshin
  File "/opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/genshin/__init__.py", line 9, in <module>
    from . import models, utility
  File "/opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/genshin/models/__init__.py", line 2, in <module>
    from .genshin import *
  File "/opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/genshin/models/genshin/__init__.py", line 2, in <module>
    from .calculator import *
  File "/opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/genshin/models/genshin/calculator.py", line 9, in <module>
    from genshin.models.model import Aliased, APIModel, Unique
  File "/opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/genshin/models/model.py", line 37, in <module>
    class APIModel(pydantic.BaseModel, abc.ABC):
  File "/opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/genshin/models/model.py", line 126, in APIModel
    @pydantic.root_validator()
     ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/pydantic/deprecated/class_validators.py", line [22](https://github.com/JJonnick/genshinStats/actions/runs/5425756902/jobs/9866931295#step:6:23)8, in root_validator
    raise PydanticUserError(
pydantic.errors.PydanticUserError: If you use `@root_validator` with pre=False (the default) you MUST specify `skip_on_failure=True`. Note that `@root_validator` is deprecated and should be replaced with `@model_validator`.

As I have seen the error comes from this line: https://github.com/thesadru/genshin.py/blob/master/genshin/models/model.py#L126

In their documentation, by adding skip_on_failure=True, seems to avoid the error or substituting with the @model_validator

thesadru commented 1 year ago

Oh did pydantic officially switch to v2?

Julius-Ulee commented 1 year ago

I'm also having the same error

thesadru commented 1 year ago

Unfortunately, the migration to pydantic v2 will need a lot of work considering genshin.py extensively modifies pydantic behavior.

Please pin your pydantic version to pydantic==1.* for now.