8000 Ffix: do not check for `__get_validators__` on classes where `__get_p… · pydantic/pydantic@c2102b7 · GitHub
[go: up one dir, main page]

Skip to content

Commit c2102b7

Browse files
authored
Ffix: do not check for __get_validators__ on classes where __get_pydantic_core_schema__ is also defined (#11444)
1 parent 6b0ba11 commit c2102b7

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

pydantic/_internal/_generate_schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ def _generate_schema_from_get_schema_method(self, obj: Any, source: Any) -> core
873873
# safety measure (because these are inlined in place -- i.e. mutated directly)
874874
return schema
875875

876-
if (validators := getattr(obj, '__get_validators__', None)) is not None:
876+
if get_schema is None and (validators := getattr(obj, '__get_validators__', None)) is not None:
877877
from pydantic.v1 import BaseModel as BaseModelV1
878878

879879
if issubclass(obj, BaseModelV1):

tests/test_edge_cases.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3023,3 +3023,17 @@ class Model(BaseModel):
30233023

30243024
m = Model(a=1)
30253025
assert m.model_dump() == {}
3026+
3027+
3028+
@pytest.mark.filterwarnings('ignore:.*`__get_validators__`.*:DeprecationWarning')
3029+
def test_get_schema_on_classes_with_both_v1_and_v2_apis() -> None:
3030+
class Model(BaseModel):
3031+
a: int
3032+
3033+
@model_validator(mode='after')
3034+
def my_model_validator(self):
3035+
return self
3036+
3037+
@classmethod
3038+
def __get_validators__(cls):
3039+
raise AssertionError('This should not be called')

0 commit comments

Comments
 (0)
0