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
Hi, I prefer to starts by a small thank you for your work, you did an amazing job with this library.
Here is a detailed description of the issue.
validation errors regression
In pydantic 2.6, for some reason the 'loc' of errors is now ('byte_size', 'constrained-str')
and not ('byte_size') for the ByteSize type. The error msg is also not clean.
The example works on pydantic 3.5.3 but failed with pydantic 2.6.0
tests/helpers/test_pydantic_2_6_migration.py::test_bytes_errors_format[invalid unit] PASSED
tests/helpers/test_pydantic_2_6_migration.py::test_bytes_errors_format[Not a Number] FAILED
_________________________________ test_bytes_errors_format[Not a Number] _________________________________
params = {'expected': [{'input': 'tenMib', 'loc': ('byte_size',), 'msg': 'could not parse value and unit from byte string', 'type': 'byte_size'}], 'input': 'tenMib'}
@pytest.mark.parametrize(
"params",
[
pytest.param(
{
"input": "4x",
"expected": [
{
"ctx": {"unit": "x"},
"input": "4x",
"loc": ("byte_size",),
"msg": "could not interpret byte unit: x",
"type": "byte_size_unit",
},
],
},
id="invalid unit",
),
pytest.param(
{
"input": "tenMib",
"expected": [
{
"input": "tenMib",
"loc": ("byte_size",),
"msg": "could not parse value and unit from byte string",
"type": "byte_size",
},
],
},
id="Not a Number",
),
],
)
def test_bytes_errors_format(params):
with pytest.raises(ValidationError) as exc:
PydanticBytes.model_validate({"byte_size": params["input"]})
> assert exc.value.errors() == params["expected"]
E assert [{'type': 'string_pattern_mismatch', 'loc': ('byte_size', 'constrained-str'), 'msg': "String should match pattern '^\\s*(\\d*\\.?\\d+)\\s*(\\w+)?'", 'input': 'tenMib', 'ctx': {'pattern': '^\\s*(\\d*\\.?\\d+)\\s*(\\w+)?'}, 'url': 'https://errors.pydantic.dev/2.6/v/string_pattern_mismatch'}, {'type': 'int
_parsing', 'loc': ('byte_size', 'constrained-int'), 'msg': 'Input should be a valid integer, unable to parse string as an integer', 'input': 'tenMib', 'url': 'https://errors.pydantic.dev/2.6/v/int_parsing'}] == [{'input': 'tenMib', 'loc': ('byte_size',), 'msg': 'could not parse value and unit from byte string', 'type'
: 'byte_size'}]
E At index 0 diff: {'type': 'string_pattern_mismatch', 'loc': ('byte_size', 'constrained-str'), 'msg': "String should match pattern '^\\s*(\\d*\\.?\\d+)\\s*(\\w+)?'", 'input': 'tenMib', 'ctx': {'pattern': '^\\s*(\\d*\\.?\\d+)\\s*(\\w+)?'}, 'url': 'https://errors.pydantic.dev/2.6/v/string_pattern_mismatch'} !=
{'input': 'tenMib', 'loc': ('byte_size',), 'msg': 'could not parse value and unit from byte string', 'type': 'byte_size'}
E Left contains one more item: {'input': 'tenMib', 'loc': ('byte_size', 'constrained-int'), 'msg': 'Input should be a valid integer, unable to parse string as an integer', 'type': 'int_parsing', ...}
E Full diff:
E [
E + {'ctx': {'pattern': '^\\s*(\\d*\\.?\\d+)\\s*(\\w+)?'},
E + 'input': 'tenMib',
E + 'loc': ('byte_size',
E + 'constrained-str'),
E + 'msg': "String should match pattern '^\\s*(\\d*\\.?\\d+)\\s*(\\w+)?'",
E + 'type': 'string_pattern_mismatch',
E + 'url': 'https://errors.pydantic.dev/2.6/v/string_pattern_mismatch'},
E {'input': 'tenMib',
E - 'loc': ('byte_size',),
E ? --
E + 'loc': ('byte_size',
E - 'msg': 'could not parse value and unit from byte string',
E - 'type': 'byte_size'},
E + 'constrained-int'),
E + 'msg': 'Input should be a valid integer, unable to parse string as an '
E + 'integer',
E + 'type': 'int_parsing',
E + 'url': 'https://errors.pydantic.dev/2.6/v/int_parsing'},
E ]
sequoia/base3/tests/helpers/test_pydantic_2_6_migration.py:47: AssertionError
Example Code
importpytestfrompydanticimportBaseModel, ByteSize, Field, ValidationErrorclassPydanticBytes(BaseModel):
byte_size: ByteSize=Field()
@pytest.mark.parametrize("params", [pytest.param( {"input": "4x","expected": [ {"ctx": {"unit": "x"},"input": "4x","loc": ("byte_size",),"msg": "could not interpret byte unit: x","type": "byte_size_unit", }, ], },id="invalid unit", ),pytest.param( {"input": "tenMib","expected": [ {"input": "tenMib","loc": ("byte_size",),"msg": "could not parse value and unit from byte string","type": "byte_size", }, ], },id="Not a Number", ), ],)deftest_bytes_errors_format(params):
withpytest.raises(ValidationError) asexc:
PydanticBytes.model_validate({"byte_size": params["input"]})
assertexc.value.errors() ==params["expected"]
Initial Checks
Description
Hi, I prefer to starts by a small thank you for your work, you did an amazing job with this library.
Here is a detailed description of the issue.
validation errors regression
In pydantic 2.6, for some reason the 'loc' of errors is now ('byte_size', 'constrained-str')
and not ('byte_size') for the ByteSize type. The error msg is also not clean.
The example works on pydantic 3.5.3 but failed with pydantic 2.6.0
Migrate to pydantic 2.6
Tests Results:
Example Code
Python, Pydantic & OS Version
The text was updated successfully, but these errors were encountered: