Jump to solution
Verify

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

Jump to Verify Open PR/Commit
@@ -2262,7 +2262,7 @@ def decode(cls, data: bytes) -> bytes: """ try: - return base64.decodebytes(data) + return base64.b64decode(data) except ValueError as e:
repro.py
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())
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==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).
Production impact:
  • 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

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…”
@sydney-runkle · 2024-03-22 · confirmation · source
“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…”
@woodruffw · 2024-09-19 · confirmation · source
“@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…”
@sydney-runkle · 2024-03-22 · source
“Example of work-around (for the record):”
@jschlyter · 2024-03-22 · source

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

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

When NOT to use: This fix should not be used if legacy behavior with newlines is required.

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!

When NOT to use: This fix should not be used if legacy behavior with newlines is required.

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.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • This fix should not be used if legacy behavior with newlines is required.

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