Skip to content

Commit

Permalink
Revert "Fix context not passed to field validators bug (#417)"
Browse files Browse the repository at this point in the history
This reverts commit 76ba2c6.
  • Loading branch information
hramezani committed Nov 1, 2024
1 parent a37d07c commit 09dfe03
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 20 deletions.
2 changes: 0 additions & 2 deletions pydantic_settings/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,6 @@ def __init__(
)
)

__init__.__pydantic_base_init__ = True # type: ignore

@classmethod
def settings_customise_sources(
cls,
Expand Down
18 changes: 0 additions & 18 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
SecretStr,
Tag,
ValidationError,
ValidationInfo,
field_validator,
)
from pydantic import (
dataclasses as pydantic_dataclasses,
Expand Down Expand Up @@ -2774,22 +2772,6 @@ class Settings(BaseSettings):
assert s.model_dump() == {'nested': {'foo': ['one', 'two']}}


def test_validation_context():
class Settings(BaseSettings):
foo: str

@field_validator('foo')
@classmethod
def test_validator(cls, v: str, info: ValidationInfo):
context = info.context
assert context == {'foo': 'bar'}
return v

s = Settings.model_validate({'foo': 'foo bar'}, context={'foo': 'bar'})
assert s.foo == 'foo bar'
assert s.model_dump() == {'foo': 'foo bar'}


def test_nested_model_field_with_alias_choices(env):
class NestedSettings(BaseModel):
foo: List[str] = Field(alias=AliasChoices('fooalias', 'foo-alias'))
Expand Down

0 comments on commit 09dfe03

Please sign in to comment.