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

2.6.0 broke model_validate_json on str | os.PathLike fields #453

Closed
jamesbraza opened this issue Oct 21, 2024 · 3 comments
Closed

2.6.0 broke model_validate_json on str | os.PathLike fields #453

jamesbraza opened this issue Oct 21, 2024 · 3 comments
Labels
duplicate This issue or pull request already exists

Comments

@jamesbraza
Copy link

This code with Python 3.12.7 and pydantic==2.9.2:

  • Works with pydantic-settings==2.5.2
  • Crashes with pydantic-settings==2.6.0
import os
from pathlib import Path

from pydantic import Field
from pydantic_settings import BaseSettings


class SomeSettings(BaseSettings):
    path: str | os.PathLike = Field(default=Path("."))


SomeSettings.model_validate_json("{}")

The error:

Traceback (most recent call last):
  File "/path/to/a.py", line 12, in <module>
    SomeSettings.model_validate_json("{}")
  File "/path/to/.venv/lib/python3.12/site-packages/pydantic/main.py", line 625, in model_validate_json
    return cls.__pydantic_validator__.validate_json(json_data, strict=strict, context=context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 2 validation errors for SomeSettings
path.str
  Input should be a valid string [type=string_type, input_value=PosixPath('.'), input_type=PosixPath]
    For further information visit https://errors.pydantic.dev/2.9/v/string_type
path.lax-or-strict[lax=union[json-or-python[json=function-after[path_validator(), str],python=is-instance[PathLike]],function-after[path_validator(), str]],strict=json-or-python[json=function-after[path_validator(), str],python=is-instance[PathLike]]]
  Input is not a valid path for <class 'os.PathLike'> [type=path_type, input_value=PosixPath('.'), input_type=PosixPath]

Process finished with exit code 1
@hramezani
Copy link
Member

Thanks @jamesbraza for reporting this issue.

This is a duplicate of #445 and caused by 76ba2c6.

please follow the original issue

@hramezani hramezani added the duplicate This issue or pull request already exists label Oct 21, 2024
@jamesbraza
Copy link
Author

Okay sure sorry didn't realize. I will close this out in favor of #445 then

@jamesbraza jamesbraza closed this as not planned Won't fix, can't repro, duplicate, stale Oct 21, 2024
@hramezani
Copy link
Member

No worries, please follow the issue. I will update the issue after we made the final decision
#445 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants