Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Pydantic2 #422

Closed
Andrew-S-Rosen opened this issue Sep 5, 2023 · 8 comments · Fixed by #440
Closed

Add support for Pydantic2 #422

Andrew-S-Rosen opened this issue Sep 5, 2023 · 8 comments · Fixed by #440

Comments

@Andrew-S-Rosen
Copy link
Member

Andrew-S-Rosen commented Sep 5, 2023

This is mainly an issue tracker to monitor the progress towards support for Pydantic 2.

Related:

@mattmcdermott
Copy link
Member

Any updates on pydantic2 support? With the recent upgrade of maggma/emmet/mp-api to pydantic2, I am now deep in dependency conflict land

@Andrew-S-Rosen
Copy link
Member Author

Andrew-S-Rosen commented Sep 27, 2023

@mattmcdermott: Check out #440! Help would be greatly appreciated while I'm on PTO! There is one failing test.

@utf utf closed this as completed in #440 Sep 28, 2023
@utf
Copy link
Member

utf commented Sep 28, 2023

Thanks for the rapid work @Andrew-S-Rosen. I've pushed a new version v0.1.14 with Pydantic2 support.

@hrushikesh-s
Copy link
Contributor

@Andrew-S-Rosen , thanks for adding Pydantic2 support to Jobflow.
I've also updated #424 accordingly.

@ViktoriiaBaib
Copy link

Hi all! I was using the following cofiguration without issues:
jobflow == 0.1.13
pydantic == 1.10.12

However, today I configured environment on a new machine, my packages:
jobflow == 0.1.14
pydantic == 2.4.2
pydantic_core == 2.10.1
pydantic-settings == 2.0.3

import jobflow as jf returns the following:

python 
Python 3.10.12 | packaged by conda-forge | (main, Jun 23 2023, 22:40:32) [GCC 12.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import jobflow as jf
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/global/homes/v/vbaib/miniconda3/envs/quacc/lib/python3.10/site-packages/jobflow/__init__.py", line 11, in <module>
    from jobflow.settings import JobflowSettings
  File "/global/homes/v/vbaib/miniconda3/envs/quacc/lib/python3.10/site-packages/jobflow/settings.py", line 29, in <module>
    class JobflowSettings(BaseSettings):
  File "/global/homes/v/vbaib/miniconda3/envs/quacc/lib/python3.10/site-packages/pydantic/_internal/_model_construction.py", line 184, in __new__
    complete_model_class(
  File "/global/homes/v/vbaib/miniconda3/envs/quacc/lib/python3.10/site-packages/pydantic/_internal/_model_construction.py", line 481, in complete_model_class
    schema = cls.__get_pydantic_core_schema__(cls, handler)
  File "/global/homes/v/vbaib/miniconda3/envs/quacc/lib/python3.10/site-packages/pydantic/main.py", line 576, in __get_pydantic_core_schema__
    return __handler(__source)
  File "/global/homes/v/vbaib/miniconda3/envs/quacc/lib/python3.10/site-packages/pydantic/_internal/_schema_generation_shared.py", line 82, in __call__
    schema = self._handler(__source_type)
  File "/global/homes/v/vbaib/miniconda3/envs/quacc/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 452, in generate_schema
    schema = self._generate_schema(obj)
  File "/global/homes/v/vbaib/miniconda3/envs/quacc/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 684, in _generate_schema
    schema = self._post_process_generated_schema(self._generate_schema_inner(obj))
  File "/global/homes/v/vbaib/miniconda3/envs/quacc/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 706, in _generate_schema_inner
    return self._model_schema(obj)
  File "/global/homes/v/vbaib/miniconda3/envs/quacc/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 525, in _model_schema
    {k: self._generate_md_field_schema(k, v, decorators) for k, v in fields.items()},
  File "/global/homes/v/vbaib/miniconda3/envs/quacc/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 525, in <dictcomp>
    {k: self._generate_md_field_schema(k, v, decorators) for k, v in fields.items()},
  File "/global/homes/v/vbaib/miniconda3/envs/quacc/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 870, in _generate_md_field_schema
    common_field = self._common_field_schema(name, field_info, decorators)
  File "/global/homes/v/vbaib/miniconda3/envs/quacc/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 923, in _common_field_schema
    schema = self._apply_annotations(
  File "/global/homes/v/vbaib/miniconda3/envs/quacc/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 1592, in _apply_annotations
    schema = get_inner_schema(source_type)
  File "/global/homes/v/vbaib/miniconda3/envs/quacc/lib/python3.10/site-packages/pydantic/_internal/_schema_generation_shared.py", line 82, in __call__
    schema = self._handler(__source_type)
  File "/global/homes/v/vbaib/miniconda3/envs/quacc/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 1576, in inner_handler
    metadata_js_function = _extract_get_pydantic_json_schema(obj, schema)
  File "/global/homes/v/vbaib/miniconda3/envs/quacc/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 1936, in _extract_get_pydantic_json_schema
    raise PydanticUserError(
pydantic.errors.PydanticUserError: The `__modify_schema__` method is not supported in Pydantic v2. Use `__get_pydantic_json_schema__` instead.

For further information visit https://errors.pydantic.dev/2.4/u/custom-json-schema

@Andrew-S-Rosen
Copy link
Member Author

@ViktoriiaBaib: Might be worth opening a new issue to ensure it gets seen. That said, I'm having trouble reproducing this error.

I made a fresh Python 3.10 environment and ran the following:

pip install jobflow==0.1.14 pydantic==2.4.2 pydantic_core==2.10.1 pydantic-settings==2.0.3

Then import jobflow as jf worked fine. Can you double-check your versions and your environment?

@ViktoriiaBaib
Copy link

That issue was caused because custodian installation downgraded monty. Doing pip install monty==2023.9.25 afterwards resolved the error.

@Andrew-S-Rosen
Copy link
Member Author

To clarify, it was because you installed the Custodian dependencies from requirements.txt rather than having them installed automatically from setup.py. The install_requires line in setup.py of Custodian has monty>=2.0.6 rather than monty==2022.9.9.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants