@@ -3145,3 +3145,45 @@ class Base(BaseModel):
31453145 ) # Create a Sub instance without triggering validation (e.g., using model_construct)
31463146 # Attempt to create Base with the Sub instance. This line should succeed if the bug is fixed, but currently raises ValidationError.
31473147 Base (sub = sub ) # <-- This throws AssertionError because Sub's 'after' validator runs again.
3148+
3149+
3150+ def test_model_validate_by_json_field_validator_with_validation_info () -> None :
3151+ """https://github.com/pydantic/pydantic/issues/13074"""
3152+
3153+ class Foo (BaseModel ):
3154+ field1 : int
3155+ field2 : int
3156+
3157+ @field_validator ('field2' )
3158+ @classmethod
3159+ def _validate_field2 (cls , v : int , info : ValidationInfo ) -> int :
3160+ assert info .field_name in ('field1' , 'field2' )
3161+ assert info .context == 'context'
3162+
3163+ return v + info .data ['field1' ]
3164+
3165+ f1 = Foo .model_validate ({'field1' : 1 , 'field2' : 2 }, context = 'context' )
3166+ f2 = Foo .model_validate_json ('{"field1": 1, "field2": 2}' , context = 'context' )
3167+
3168+ assert f1 .field1 == f2 .field1 == 1
3169+ assert f1 .field2 == f2 .field2 == 3
3170+
3171+
3172+ def test_model_validate_json_default_value_validator_with_validation_info () -> None :
3173+ """https://github.com/pydantic/pydantic/issues/13074"""
3174+
3175+ class Foo (BaseModel , validate_default = True ):
3176+ field : int = 1
3177+
3178+ @field_validator ('field' )
3179+ @classmethod
3180+ def _validate_field (cls , v : int , info : ValidationInfo ) -> int :
3181+ assert info .field_name == 'field'
3182+ assert info .context == 'context'
3183+
3184+ return v + 1
3185+
3186+ f1 = Foo .model_validate ({'field' : 1 }, context = 'context' )
3187+ f2 = Foo .model_validate_json ('{"field1": 1}' , context = 'context' )
3188+
3189+ assert f1 .field == f2 .field == 2
0 commit comments