The Fix
pip install pydantic==1.10.19
Based on closed pydantic/pydantic issue #9072 · PR/commit linked
Production note: Most teams hit this during upgrades or environment changes. Roll out with a canary and smoke critical endpoints (health, OpenAPI/docs) before 100%.
@@ -2262,7 +2262,7 @@ def decode(cls, data: bytes) -> bytes:
"""
try:
- return base64.decodebytes(data)
+ return base64.b64decode(data)
except ValueError as e:
import os
from base64 import b64encode
from pydantic import Base64Bytes, BaseModel
class Foo(BaseModel):
random: Base64Bytes
print(Foo(random=b64encode(os.urandom(32)).decode()).model_dump_json())
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==1.10.19\nWhen NOT to use: This fix should not be used if legacy behavior with newlines is required.\n\nOption C — Workaround\nfor others to reference!\nWhen NOT to use: This fix should not be used if legacy behavior with newlines is required.\n\n
Why This Fix Works in Production
- Trigger: I'm concerned that implementing a change under the hood would cause breaking changes for existing users, and if it's easy enough to customize, I think this…
- Mechanism: Base64Bytes used encodebytes which adds newlines, causing compatibility issues with some decoders
- Why the fix works: Changes the encoding method used in the Base64Bytes type from encodebytes to b64encode to prevent unwanted newlines in the output. (first fixed release: 1.10.19).
- If left unfixed, the same config can fail only in production (env differences), causing startup failures or partial feature outages.
Why This Breaks in Prod
- Shows up under Python 3.12 in real deployments (not just unit tests).
- Base64Bytes used encodebytes which adds newlines, causing compatibility issues with some decoders
- Production symptom (often without a traceback): python version: 3.12.2 (main, Feb 6 2024, 20:19:44) [Clang 15.0.0 (clang-1500.1.0.2.5)]
Proof / Evidence
- GitHub issue: #9072
- Fix PR: https://github.com/pydantic/pydantic/pull/10486
- First fixed release: 1.10.19
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.85
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.64
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“Right, I understand the sentiment, but given that it's easy to change on the user side of things with a custom encoder, I don't think…”
“Hey @sydney-runkle! I can understand why this can't be immediately changed for compatibility reasons, but I wanted to add another datapoint here: this recently bit…”
“@jschlyter, I'm concerned that implementing a change under the hood would cause breaking changes for existing users, and if it's easy enough to customize, I…”
“Example of work-around (for the record):”
Failure Signature (Search String)
- I'm concerned that implementing a change under the hood would cause breaking changes for existing users, and if it's easy enough to customize, I think this kind of change might be
Copy-friendly signature
Failure Signature
-----------------
python version: 3.12.2 (main, Feb 6 2024, 20:19:44) [Clang 15.0.0 (clang-1500.1.0.2.5)]
I'm concerned that implementing a change under the hood would cause breaking changes for existing users, and if it's easy enough to customize, I think this kind of change might be best in user code...
Error Message
Signature-only (no traceback captured)
Error Message
-------------
python version: 3.12.2 (main, Feb 6 2024, 20:19:44) [Clang 15.0.0 (clang-1500.1.0.2.5)]
I'm concerned that implementing a change under the hood would cause breaking changes for existing users, and if it's easy enough to customize, I think this kind of change might be best in user code...
Minimal Reproduction
import os
from base64 import b64encode
from pydantic import Base64Bytes, BaseModel
class Foo(BaseModel):
random: Base64Bytes
print(Foo(random=b64encode(os.urandom(32)).decode()).model_dump_json())
Environment
- Python: 3.12
- Pydantic: 2
What Broke
Newlines in base64 output caused decoding failures in production systems.
Why It Broke
Base64Bytes used encodebytes which adds newlines, causing compatibility issues with some decoders
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install pydantic==1.10.19
Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.
Option C — Workaround Temporary workaround
for others to reference!
Use only if you cannot change versions today. Treat this as a stopgap and remove once upgraded.
Fix reference: https://github.com/pydantic/pydantic/pull/10486
First fixed release: 1.10.19
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix should not be used if legacy behavior with newlines is required.
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 |
|---|---|
| 1.10.19 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.