Jump to solution
Verify

The Fix

pip install pydantic==2.6.1

Based on closed pydantic/pydantic issue #8676 · PR/commit linked

Jump to Verify Open PR/Commit
@@ -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',
repro.py
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"]
verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
fix.md
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).
Production impact:
  • 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

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!”
@sydney-runkle · 2024-01-30 · source
“Broken in this PR: https://github.com/pydantic/pydantic/pull/8537/files”
@sydney-runkle · 2024-01-30 · source
“@mardiros, I've opened a PR that should fix this issue. Thanks for bringing this to our attention!”
@sydney-runkle · 2024-01-30 · source

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
signature.txt
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.txt
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

repro.py
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

When NOT to use: Do not use if it changes public behavior or if the failure cannot be reproduced.

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.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • Do not use if it changes public behavior or if the failure cannot be reproduced.

Verify Fix

verify
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

VersionStatus
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.