The Fix
pip install pydantic==2.12.0
Based on closed pydantic/pydantic issue #9571 · PR/commit linked
@@ -2,28 +2,31 @@
---
-Pydantic supports many common types from the Python standard library. If you need stricter processing see
-[Strict Types](../concepts/types.md#strict-types), including if you need to constrain the values allowed (e.g. to require a positive `int`).
+This section enumerates the supported built-in and standard library types: the allowed values,
>> pyenv virtualenv 3.9.5 pydanticv1
>> pyenv activate pydanticv1
>> pip install 'pydantic<2'
>> ipython
In [1]: from datetime import datetime, timezone
In [2]: from pydantic import BaseModel
In [3]: class Foo(BaseModel):
...: dt: datetime
...:
In [4]: foo = Foo(dt=datetime.now(tz=timezone.utc))
In [5]: foo.json()
Out[5]: '{"dt": "2024-06-17T15:32:31.825334+00:00"}'
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.12.0\nWhen NOT to use: Do not use this fix if you require strict timezone handling without errors.\n\n
Why This Fix Works in Production
- Trigger: We should almost certainly not do this. I think our best options are either to serialise the timezone name (hard but powerful) or to error (correct but…
- Mechanism: Time serialization drops timezone information when using non-trivial offsets
- Why the fix works: Rewrites the standard library types documentation to centralize information about validation, constraints, and serialization, addressing the issue of time serialization dropping timezone. (first fixed release: 2.12.0).
- If left unfixed, this can cause silent data inconsistencies that propagate (bad cache entries, incorrect downstream decisions).
Why This Breaks in Prod
- Triggered by an upgrade/regression window: 31.825334 breaks; 2.12.0 is the first fixed release.
- Time serialization drops timezone information when using non-trivial offsets
- Production symptom (often without a traceback): We should almost certainly not do this. I think our best options are either to serialise the timezone name (hard but powerful) or to error (correct but frustrating for users).
Proof / Evidence
- GitHub issue: #9571
- Fix PR: https://github.com/pydantic/pydantic/pull/12287
- First fixed release: 2.12.0
- Affected versions: 31.825334
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.95
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.58
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“I think what we should do is support RFC 9557. It looks like the correct thing to do is to serialize the UTC offset as…”
“While that's in progress, here's a band-aid for anyone else having issues with Z suddenly appearing in your timestamps: And just use DateTime instead of…”
“Hello! While migrating one of our FastAPI apps from pydanticv1 to pydanticv2, I also noticed that this behavior differs between the two pydantic versions. With…”
“Thanks @davidhewitt, I've added this to the v2.8.0 milestone!”
Failure Signature (Search String)
- We should almost certainly not do this. I think our best options are either to serialise the timezone name (hard but powerful) or to error (correct but frustrating for users).
Copy-friendly signature
Failure Signature
-----------------
We should almost certainly not do this. I think our best options are either to serialise the timezone name (hard but powerful) or to error (correct but frustrating for users).
python version: 3.12.3 (main, May 8 2024, 09:46:04) [Clang 15.0.0 (clang-1500.3.9.4)]
Error Message
Signature-only (no traceback captured)
Error Message
-------------
We should almost certainly not do this. I think our best options are either to serialise the timezone name (hard but powerful) or to error (correct but frustrating for users).
python version: 3.12.3 (main, May 8 2024, 09:46:04) [Clang 15.0.0 (clang-1500.3.9.4)]
Minimal Reproduction
>> pyenv virtualenv 3.9.5 pydanticv1
>> pyenv activate pydanticv1
>> pip install 'pydantic<2'
>> ipython
In [1]: from datetime import datetime, timezone
In [2]: from pydantic import BaseModel
In [3]: class Foo(BaseModel):
...: dt: datetime
...:
In [4]: foo = Foo(dt=datetime.now(tz=timezone.utc))
In [5]: foo.json()
Out[5]: '{"dt": "2024-06-17T15:32:31.825334+00:00"}'
Environment
- Pydantic: 2
What Broke
Users experience inconsistent serialization results for time objects with timezones.
Why It Broke
Time serialization drops timezone information when using non-trivial offsets
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install pydantic==2.12.0
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/12287
First fixed release: 2.12.0
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- Do not use this fix if you require strict timezone handling without errors.
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 |
|---|---|
| 31.825334 | Broken |
| 2.12.0 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.