ncar-xdev / ecgtools

ESM Catalog Generation tools
https://ecgtools.readthedocs.io
Apache License 2.0
9 stars 11 forks source link

[Bug]: Updates needed for pydantic v2 #161

Closed dougiesquire closed 1 year ago

dougiesquire commented 1 year ago

What happened?

Pydantic v2 was released on July 1. Ecgtools uses pydantic, but does not work with pydantic v2. Simply importing ecgtools with pydantic=v2.0 results in an error.

What did you expect to happen?

Able to use ecgtools with pydantic v2

Minimal Complete Verifiable Example

# With pydantic=v2.0
import ecgtools

Relevant log output

~/miniconda3/envs/test/lib/python3.11/site-packages/pydantic/_internal/_config.py:257: UserWarning: Valid config keys have changed in V2:
* 'validate_all' has been renamed to 'validate_default'
  warnings.warn(message, UserWarning)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "~/miniconda3/envs/test/lib/python3.11/site-packages/ecgtools/__init__.py", line 6, in <module>
    from .builder import Builder, RootDirectory, glob_to_regex
  File "~/miniconda3/envs/test/lib/python3.11/site-packages/ecgtools/builder.py", line 13, in <module>
    from intake_esm.cat import (
  File "~/miniconda3/envs/test/lib/python3.11/site-packages/intake_esm/__init__.py", line 9, in <module>
    from .core import esm_datastore
  File "~/miniconda3/envs/test/lib/python3.11/site-packages/intake_esm/core.py", line 21, in <module>
    from .cat import ESMCatalogModel
  File "~/miniconda3/envs/test/lib/python3.11/site-packages/intake_esm/cat.py", line 68, in <module>
    class Assets(pydantic.BaseModel):
  File "~/miniconda3/envs/test/lib/python3.11/site-packages/intake_esm/cat.py", line 77, in Assets
    @pydantic.root_validator
     ^^^^^^^^^^^^^^^^^^^^^^^
  File "~/miniconda3/envs/test/lib/python3.11/site-packages/pydantic/deprecated/class_validators.py", line 222, in root_validator
    return root_validator()(*__args)  # type: ignore
           ^^^^^^^^^^^^^^^^
  File "~/miniconda3/envs/test/lib/python3.11/site-packages/pydantic/deprecated/class_validators.py", line 228, 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`.

For further information visit https://errors.pydantic.dev/2.0/u/root-validator-pre-skip

Anything else we need to know?

This should be a pretty straightforward update. I'm happy to submit a PR if wanted.

dcherian commented 1 year ago

Thanks for posting @dougiesquire . A PR would be great. Unfortunately ecgtools is mostly unmaintained at the moment.

I am going to give you maintainer privileges here :)

dougiesquire commented 1 year ago

Actually, I don't think there are any pydantic-related changes need in ecgtools. The issue comes because updates are needed in Intake-ESM, which ecgtools uses. I've opened an issue with Intake-ESM (see https://github.com/intake/intake-esm/issues/617). Once that is resolved, I'll remove the pydantic version pins I added in #162 and close this issue.

dougiesquire commented 1 year ago

Actually (again), my previous post is not correct. There are a few changes needed. I'll make a PR now.