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
after upgrading my Pydantic version to 2.10.x, I noticed that my Pydjantic settings for my project prevent it from starting up. This is my settings definition:
class DatabaseSettings(pydjantic.BaseDBConfig):
default: t.Annotated[
pydantic.PostgresDsn, pydantic.Field(
validation_alias='DATABASE_URL',
json_schema_extra={'test_options': {'MIGRATE': False}}
)
]
class DjangoSettings(BaseSettings):
DATABASES: DatabaseSettings = DatabaseSettings()
The crash happens in django.db.utils, in the configure_settings method, where the line conn.setdefault("ATOMIC_REQUESTS", False) raises AttributeError: 'PostgresDsn' object has no attribute 'setdefault'.
This seems to be due to a Pydantic internal change (I'm suspecting this PR: pydantic/pydantic#10662), causing the if not isinstance(value, (str, MultiHostUrl)): check to be hit in the field validator method of the BaseDBConfig class, and the value, the PostgresDsn instance, being returned as-is. Apparently there's some inheritance change.
This can be prevented by importing the private base class from which PostgresDsn currently inherits from and adding it in the tuple:
from pydantic.networks import _BaseMultiHostUrl
class BaseDBConfig(BaseSettings):
...
@field_validator('*')
def format_config_from_dsn(cls, value: Any, info: ValidationInfo):
if value is None:
return {}
if not isinstance(value, (str, MultiHostUrl, _BaseMultiHostUrl)):
return value
....
but of course that's not an exhaustive solution.
The text was updated successfully, but these errors were encountered:
Hi,
after upgrading my Pydantic version to 2.10.x, I noticed that my Pydjantic settings for my project prevent it from starting up. This is my settings definition:
The crash happens in
django.db.utils
, in theconfigure_settings
method, where the lineconn.setdefault("ATOMIC_REQUESTS", False)
raisesAttributeError: 'PostgresDsn' object has no attribute 'setdefault'
.This seems to be due to a Pydantic internal change (I'm suspecting this PR: pydantic/pydantic#10662), causing the
if not isinstance(value, (str, MultiHostUrl)):
check to be hit in the field validator method of the BaseDBConfig class, and thevalue
, the PostgresDsn instance, being returned as-is. Apparently there's some inheritance change.This can be prevented by importing the private base class from which PostgresDsn currently inherits from and adding it in the tuple:
but of course that's not an exhaustive solution.
The text was updated successfully, but these errors were encountered: