The Fix
pip install pydantic==2.6.1
Based on closed pydantic/pydantic issue #8676 · PR/commit linked
@@ -1787,7 +1787,9 @@ def __get_pydantic_core_schema__(cls, source: type[Any], handler: GetCoreSchemaH
core_schema.str_schema(pattern=cls.byte_string_pattern),
core_schema.int_schema(ge=0),
- ]
+ ],
+ custom_error_type='byte_size',
import pytest
from pydantic import BaseModel, ByteSize, Field, ValidationError
class PydanticBytes(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",
),
],
)
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"]
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Option A — Upgrade to fixed release\npip install pydantic==2.6.1\nWhen NOT to use: Do not use if it changes public behavior or if the failure cannot be reproduced.\n\n
Why This Fix Works in Production
- Trigger: Regression in ByteSize error after migrating to pydantic 2.6
- Mechanism: Fixes the ByteSize validation error type change that caused validation errors to be reported incorrectly in Pydantic 2.6.
- Why the fix works: Fixes the ByteSize validation error type change that caused validation errors to be reported incorrectly in Pydantic 2.6. (first fixed release: 2.6.1).
- If left unfixed, this can cause silent data inconsistencies that propagate (bad cache entries, incorrect downstream decisions).
Why This Breaks in Prod
- Shows up under Python 3.11 in real deployments (not just unit tests).
- Production symptom (often without a traceback): Regression in ByteSize error after migrating to pydantic 2.6
Proof / Evidence
- GitHub issue: #8676
- Fix PR: https://github.com/pydantic/pydantic/pull/8681
- First fixed release: 2.6.1
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.75
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.36
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“@mardiros, Thanks for the report. We'll look into a fix for this to be included in a patch release soon!”
“Broken in this PR: https://github.com/pydantic/pydantic/pull/8537/files”
“@mardiros, I've opened a PR that should fix this issue. Thanks for bringing this to our attention!”
Failure Signature (Search String)
- Regression in ByteSize error after migrating to pydantic 2.6
- In pydantic 2.6, for some reason the 'loc' of errors is now ('byte_size', 'constrained-str')
Copy-friendly signature
Failure Signature
-----------------
Regression in ByteSize error after migrating to pydantic 2.6
In pydantic 2.6, for some reason the 'loc' of errors is now ('byte_size', 'constrained-str')
Error Message
Signature-only (no traceback captured)
Error Message
-------------
Regression in ByteSize error after migrating to pydantic 2.6
In pydantic 2.6, for some reason the 'loc' of errors is now ('byte_size', 'constrained-str')
Minimal Reproduction
import pytest
from pydantic import BaseModel, ByteSize, Field, ValidationError
class PydanticBytes(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",
),
],
)
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"]
Environment
- Python: 3.11
- Pydantic: 2.6
What Broke
Validation errors for ByteSize type were reported incorrectly, leading to confusion in error handling.
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install pydantic==2.6.1
Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.
Fix reference: https://github.com/pydantic/pydantic/pull/8681
First fixed release: 2.6.1
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- Do not use if it changes public behavior or if the failure cannot be reproduced.
Verify Fix
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Did This Fix Work in Your Case?
Quick signal helps us prioritize which fixes to verify and improve.
Prevention
- Add a CI check that diffs key outputs after upgrades (OpenAPI schema snapshots, JSON payload shapes, CLI output).
- Upgrade behind a canary and run integration tests against the canary before 100% rollout.
Version Compatibility Table
| Version | Status |
|---|---|
| 2.6.1 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.