Skip to content

Commit 7642acc

Browse files
committed
Revert changes to model-fields and dataclass
1 parent b9e0f5c commit 7642acc

File tree

5 files changed

+1
-140
lines changed

5 files changed

+1
-140
lines changed

python/pydantic_core/core_schema.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class CoreConfig(TypedDict, total=False):
9696
validate_default: bool
9797
# used on typed-dicts and arguments
9898
populate_by_name: bool # replaces `allow_population_by_field_name` in pydantic v1
99-
# stop validation on a first error, used with typed-dict, model-fields, and dataclass fields
99+
# stop validation on a first error, used with typed-dict
100100
fail_fast: bool
101101
# fields related to string fields only
102102
str_max_length: int
@@ -3004,7 +3004,6 @@ class ModelFieldsSchema(TypedDict, total=False):
30043004
# all these values can be set via config, equivalent fields have `typed_dict_` prefix
30053005
extra_behavior: ExtraBehavior
30063006
populate_by_name: bool # replaces `allow_population_by_field_name` in pydantic v1
3007-
fail_fast: bool # default: False
30083007
from_attributes: bool
30093008
ref: str
30103009
metadata: Dict[str, Any]
@@ -3021,7 +3020,6 @@ def model_fields_schema(
30213020
extra_behavior: ExtraBehavior | None = None,
30223021
populate_by_name: bool | None = None,
30233022
from_attributes: bool | None = None,
3024-
fail_fast: bool | None = None,
30253023
ref: str | None = None,
30263024
metadata: Dict[str, Any] | None = None,
30273025
serialization: SerSchema | None = None,
@@ -3051,7 +3049,6 @@ def model_fields_schema(
30513049
extra_behavior: The extra behavior to use for the typed dict
30523050
populate_by_name: Whether the typed dict should populate by name
30533051
from_attributes: Whether the typed dict should be populated from attributes
3054-
fail_fast: Stop validation on the first error
30553052
serialization: Custom serialization schema
30563053
"""
30573054
return _dict_not_none(
@@ -3064,7 +3061,6 @@ def model_fields_schema(
30643061
extra_behavior=extra_behavior,
30653062
populate_by_name=populate_by_name,
30663063
from_attributes=from_attributes,
3067-
fail_fast=fail_fast,
30683064
ref=ref,
30693065
metadata=metadata,
30703066
serialization=serialization,
@@ -3248,7 +3244,6 @@ class DataclassArgsSchema(TypedDict, total=False):
32483244
fields: Required[List[DataclassField]]
32493245
computed_fields: List[ComputedField]
32503246
populate_by_name: bool # default: False
3251-
fail_fast: bool # default: False
32523247
collect_init_only: bool # default: False
32533248
ref: str
32543249
metadata: Dict[str, Any]
@@ -3262,7 +3257,6 @@ def dataclass_args_schema(
32623257
*,
32633258
computed_fields: List[ComputedField] | None = None,
32643259
populate_by_name: bool | None = None,
3265-
fail_fast: bool | None = None,
32663260
collect_init_only: bool | None = None,
32673261
ref: str | None = None,
32683262
metadata: Dict[str, Any] | None = None,
@@ -3291,7 +3285,6 @@ def dataclass_args_schema(
32913285
fields: The fields to use for the dataclass
32923286
computed_fields: Computed fields to use when serializing the dataclass
32933287
populate_by_name: Whether to populate by name
3294-
fail_fast: Stop validation on the first error
32953288
collect_init_only: Whether to collect init only fields into a dict to pass to `__post_init__`
32963289
ref: optional unique identifier of the schema, used to reference the schema in other places
32973290
metadata: Any other information you want to include with the schema, not used by pydantic-core
@@ -3304,7 +3297,6 @@ def dataclass_args_schema(
33043297
fields=fields,
33053298
computed_fields=computed_fields,
33063299
populate_by_name=populate_by_name,
3307-
fail_fast=fail_fast,
33083300
collect_init_only=collect_init_only,
33093301
ref=ref,
33103302
metadata=metadata,

src/validators/dataclass.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ pub struct DataclassArgsValidator {
4040
validator_name: String,
4141
extra_behavior: ExtraBehavior,
4242
extras_validator: Option<Box<CombinedValidator>>,
43-
fail_fast: bool,
4443
loc_by_alias: bool,
4544
}
4645

@@ -55,7 +54,6 @@ impl BuildValidator for DataclassArgsValidator {
5554
let py = schema.py();
5655

5756
let populate_by_name = schema_or_config_same(schema, config, intern!(py, "populate_by_name"))?.unwrap_or(false);
58-
let fail_fast = schema_or_config_same(schema, config, intern!(py, "fail_fast"))?.unwrap_or(false);
5957

6058
let extra_behavior = ExtraBehavior::from_schema_or_config(py, schema, config, ExtraBehavior::Ignore)?;
6159

@@ -130,7 +128,6 @@ impl BuildValidator for DataclassArgsValidator {
130128
validator_name,
131129
extra_behavior,
132130
extras_validator,
133-
fail_fast,
134131
loc_by_alias: config.get_as(intern!(py, "loc_by_alias"))?.unwrap_or(true),
135132
}
136133
.into())
@@ -177,10 +174,6 @@ impl Validator for DataclassArgsValidator {
177174

178175
// go through fields getting the value from args or kwargs and validating it
179176
for (index, field) in self.fields.iter().enumerate() {
180-
if self.fail_fast && !errors.is_empty() {
181-
break;
182-
}
183-
184177
if !field.init {
185178
match field.validator.default_value(py, Some(field.name.as_str()), state) {
186179
Ok(Some(value)) => {
@@ -298,10 +291,6 @@ impl Validator for DataclassArgsValidator {
298291
if let Some(kwargs) = args.kwargs() {
299292
if kwargs.len() != used_keys.len() {
300293
for result in kwargs.iter() {
301-
if self.fail_fast && !errors.is_empty() {
302-
break;
303-
}
304-
305294
let (raw_key, value) = result?;
306295
match raw_key
307296
.borrow_input()

src/validators/model_fields.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ pub struct ModelFieldsValidator {
3636
strict: bool,
3737
from_attributes: bool,
3838
loc_by_alias: bool,
39-
fail_fast: bool,
4039
}
4140

4241
impl BuildValidator for ModelFieldsValidator {
@@ -52,7 +51,6 @@ impl BuildValidator for ModelFieldsValidator {
5251

5352
let from_attributes = schema_or_config_same(schema, config, intern!(py, "from_attributes"))?.unwrap_or(false);
5453
let populate_by_name = schema_or_config_same(schema, config, intern!(py, "populate_by_name"))?.unwrap_or(false);
55-
let fail_fast = schema_or_config_same(schema, config, intern!(py, "fail_fast"))?.unwrap_or(false);
5654

5755
let extra_behavior = ExtraBehavior::from_schema_or_config(py, schema, config, ExtraBehavior::Ignore)?;
5856

@@ -104,7 +102,6 @@ impl BuildValidator for ModelFieldsValidator {
104102
extras_validator,
105103
strict,
106104
from_attributes,
107-
fail_fast,
108105
loc_by_alias: config.get_as(intern!(py, "loc_by_alias"))?.unwrap_or(true),
109106
}
110107
.into())
@@ -171,10 +168,6 @@ impl Validator for ModelFieldsValidator {
171168
let state = &mut state.rebind_extra(|extra| extra.data = Some(model_dict.clone()));
172169

173170
for field in &self.fields {
174-
if self.fail_fast && !errors.is_empty() {
175-
break;
176-
}
177-
178171
let op_key_value = match dict.get_item(&field.lookup_key) {
179172
Ok(v) => v,
180173
Err(ValError::LineErrors(line_errors)) => {

tests/validators/test_dataclasses.py

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,63 +1713,3 @@ class Foo:
17131713
assert exc_info.value.errors(include_url=False) == expected.errors
17141714
else:
17151715
assert dataclasses.asdict(v.validate_python(input_value)) == expected
1716-
1717-
1718-
@pytest.mark.parametrize(
1719-
('fail_fast', 'expected'),
1720-
[
1721-
pytest.param(
1722-
True,
1723-
[
1724-
{
1725-
'type': 'string_type',
1726-
'loc': ('a',),
1727-
'msg': 'Input should be a valid string',
1728-
'input': 10,
1729-
},
1730-
],
1731-
id='fail_fast',
1732-
),
1733-
pytest.param(
1734-
False,
1735-
[
1736-
{
1737-
'type': 'string_type',
1738-
'loc': ('a',),
1739-
'msg': 'Input should be a valid string',
1740-
'input': 10,
1741-
},
1742-
{
1743-
'type': 'string_type',
1744-
'loc': ('b',),
1745-
'msg': 'Input should be a valid string',
1746-
'input': 20,
1747-
},
1748-
],
1749-
id='not_fail_fast',
1750-
),
1751-
],
1752-
)
1753-
def test_dataclass_fail_fast(fail_fast, expected):
1754-
@dataclasses.dataclass
1755-
class Foo:
1756-
a: str
1757-
b: str
1758-
1759-
schema = core_schema.dataclass_schema(
1760-
Foo,
1761-
core_schema.dataclass_args_schema(
1762-
'Foo',
1763-
[
1764-
core_schema.dataclass_field(name='a', schema=core_schema.str_schema()),
1765-
core_schema.dataclass_field(name='b', schema=core_schema.str_schema()),
1766-
],
1767-
fail_fast=fail_fast,
1768-
),
1769-
['a', 'b'],
1770-
)
1771-
1772-
with pytest.raises(ValidationError) as exc_info:
1773-
SchemaValidator(schema).validate_python({'a': 10, 'b': 20})
1774-
1775-
assert exc_info.value.errors(include_url=False) == expected

tests/validators/test_model_fields.py

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,56 +1781,3 @@ def test_extra_behavior_ignore(config: Union[core_schema.CoreConfig, None], sche
17811781
}
17821782
]
17831783
assert 'not_f' not in m
1784-
1785-
1786-
@pytest.mark.parametrize(
1787-
('fail_fast', 'expected'),
1788-
[
1789-
pytest.param(
1790-
True,
1791-
[
1792-
{
1793-
'input': 'x',
1794-
'loc': ('a',),
1795-
'msg': 'Input should be a valid integer, unable to parse string as an integer',
1796-
'type': 'int_parsing',
1797-
},
1798-
],
1799-
id='fail_fast',
1800-
),
1801-
pytest.param(
1802-
False,
1803-
[
1804-
{
1805-
'input': 'x',
1806-
'loc': ('a',),
1807-
'msg': 'Input should be a valid integer, unable to parse string as an integer',
1808-
'type': 'int_parsing',
1809-
},
1810-
{
1811-
'input': 'y',
1812-
'loc': ('b',),
1813-
'msg': 'Input should be a valid integer, unable to parse string as an integer',
1814-
'type': 'int_parsing',
1815-
},
1816-
],
1817-
id='not_fail_fast',
1818-
),
1819-
],
1820-
)
1821-
def test_model_fields_fail_fast(fail_fast, expected):
1822-
v = SchemaValidator(
1823-
{
1824-
'type': 'model-fields',
1825-
'fields': {
1826-
'a': {'type': 'model-field', 'schema': {'type': 'int'}},
1827-
'b': {'type': 'model-field', 'schema': {'type': 'int'}},
1828-
},
1829-
'fail_fast': fail_fast,
1830-
},
1831-
)
1832-
1833-
with pytest.raises(ValidationError) as exc_info:
1834-
v.validate_python({'a': 'x', 'b': 'y'})
1835-
1836-
assert exc_info.value.errors(include_url=False) == expected

0 commit comments

Comments
 (0)