You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I noticed that a pattern I was using before is not working well anymore. I am using pydantic-settings (version 2.0.0), which is now a separate package, for settings management. Possibly I should create this issue at pydantic-settings instead of here. My excuses if that is the case, I can also do that of course.
What I observed is the following. It used to be possible to do this:
That worked well in the past. The string in the .env file was converted to a UPath object by pydantic.
Now it gives me this error:
ImportError while loading conftest '..../tests/conftest.py'.
tests/conftest.py:6: in <module>
from bigwig_loader.collection import BigWigCollection
bigwig_loader/__init__.py:15: in <module>
config = _Settings()
mambaforge/envs/bigwig/lib/python3.11/site-packages/pydantic_settings/main.py:61: in __init__
super().__init__(
E pydantic_core._pydantic_core.ValidationError: 1 validation error for Settings
E example_data_dir
E Input should be an instance of UPath [type=is_instance_of, input_value=PosixPath('/bla/bla/r.../example_data'), input_type=PosixPath]
E For further information visit https://errors.pydantic.dev/2.0.1/v/is_instance_of
It seems like pydantic-settings is more strict than it used to be or something changed with the types of universal_pathlib?
universal_pathlib version: 0.0.23
operating system: RHEL 7.9 and macOS
The text was updated successfully, but these errors were encountered:
I found out that this is not just happening with the .env file. It actually is just variable assignment that already causes the problem. If I make the minimal change to:
from dotenv import find_dotenv
from pydantic import BaseConfig
from pydantic_settings import BaseSettings
from upath import UPath
class Settings(BaseSettings):
example_path: Path = UPath(__file__).parent.parent / "example_data"
class Config(BaseConfig):
env_prefix = "my_env_"
env_file = find_dotenv(".env")
env_file_encoding = 'utf-8'
the error is gone. But that is a pity as it reduces flexibility, because when I now have "s3:/some/path" in my .env file it is converted to a pathlib.Path object instead of a UPath object.
ap--
changed the title
UPath does not play with pedantic-settings like it used to
UPath does not play with pydantic-settings like it used to
Jul 5, 2023
Hi,
I noticed that a pattern I was using before is not working well anymore. I am using pydantic-settings (version 2.0.0), which is now a separate package, for settings management. Possibly I should create this issue at pydantic-settings instead of here. My excuses if that is the case, I can also do that of course.
What I observed is the following. It used to be possible to do this:
and I created a .env file with:
That worked well in the past. The string in the .env file was converted to a UPath object by pydantic.
Now it gives me this error:
It seems like pydantic-settings is more strict than it used to be or something changed with the types of universal_pathlib?
universal_pathlib version: 0.0.23
operating system: RHEL 7.9 and macOS
The text was updated successfully, but these errors were encountered: