Jump to solution
Verify

The Fix

pip install pydantic==1.10.1

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

Jump to Verify Open PR/Commit
@@ -7,7 +7,7 @@ isort==4.3.21 pycodestyle==2.5.0 pyflakes==2.1.1 -pytest==5.3.4 +pytest==5.3.5 pytest-cov==2.8.1
repro.py
import datetime from pydantic import BaseModel class Event(BaseModel): dt: datetime.datetime = None event = Event(dt="2024-01-01T13:56:57.115Z") print("This should be True:", event.dt.tzinfo == datetime.UTC) # prints: This should be True: False
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.1\nWhen NOT to use: This fix should not be applied if relying on custom timezone comparisons.\n\n

Why This Fix Works in Production

  • Trigger: A Pydantic model with a `datetime.datetime` attribute and initialized with an UTC timestamp fails to correctly compare its `.tzinfo` attribute to…
  • Mechanism: Addresses the issue of incorrect comparison of Pydantic's TzInfo with datetime.UTC by implementing necessary equality checks.
  • Why the fix works: Addresses the issue of incorrect comparison of Pydantic's TzInfo with datetime.UTC by implementing necessary equality checks. (first fixed release: 1.10.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): A Pydantic model with a `datetime.datetime` attribute and initialized with an UTC timestamp fails to correctly compare its `.tzinfo` attribute to `datetime.UTC` for equality.

Proof / Evidence

Discussion

High-signal excerpts from the issue thread (symptoms, repros, edge-cases).

“@gkoller, Thanks for reporting this”
@sydney-runkle · 2024-02-02 · source
“don't we just need to fix TzInfo::__richcmp__?”
@samuelcolvin · 2024-02-02 · source
“We could definitely implement comparisons for pydantic_core.TzInfo with fixed-offset datetime.timezone, which I think would fix the UTC case”
@davidhewitt · 2024-02-02 · source
“Note that Python’s own standard library has many different UTC zone objects: for example, datetime.UTC, zoneinfo.ZoneInfo("UCT"), zoneinfo.ZoneInfo("UTC"), zoneinfo.ZoneInfo("Universal"), zoneinfo.ZoneInfo("Zulu"), zoneinfo.ZoneInfo("Etc/UCT"), zoneinfo.ZoneIn”
@andersk · 2024-02-02 · source

Failure Signature (Search String)

  • A Pydantic model with a `datetime.datetime` attribute and initialized with an UTC timestamp fails to correctly compare its `.tzinfo` attribute to `datetime.UTC` for equality.
  • Though It is a change in behaviour from Pydantic V1 to V2 and probably should be documented as such somewhere in the [Migration Guide](https://docs.pydantic.dev/latest/migration).
Copy-friendly signature
signature.txt
Failure Signature ----------------- A Pydantic model with a `datetime.datetime` attribute and initialized with an UTC timestamp fails to correctly compare its `.tzinfo` attribute to `datetime.UTC` for equality. Though It is a change in behaviour from Pydantic V1 to V2 and probably should be documented as such somewhere in the [Migration Guide](https://docs.pydantic.dev/latest/migration).

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- A Pydantic model with a `datetime.datetime` attribute and initialized with an UTC timestamp fails to correctly compare its `.tzinfo` attribute to `datetime.UTC` for equality. Though It is a change in behaviour from Pydantic V1 to V2 and probably should be documented as such somewhere in the [Migration Guide](https://docs.pydantic.dev/latest/migration).

Minimal Reproduction

repro.py
import datetime from pydantic import BaseModel class Event(BaseModel): dt: datetime.datetime = None event = Event(dt="2024-01-01T13:56:57.115Z") print("This should be True:", event.dt.tzinfo == datetime.UTC) # prints: This should be True: False

Environment

  • Python: 3.11
  • Pydantic: 2

What Broke

Comparisons of datetime objects with UTC timestamps fail, leading to incorrect behavior.

Fix Options (Details)

Option A — Upgrade to fixed release Safe default (recommended)

pip install pydantic==1.10.1

When NOT to use: This fix should not be applied if relying on custom timezone comparisons.

Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.

Fix reference: https://github.com/pydantic/pydantic-core/pull/1197

First fixed release: 1.10.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

  • This fix should not be applied if relying on custom timezone comparisons.

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

Related Issues

No related fixes found.

Sources

We don’t republish the full GitHub discussion text. Use the links above for context.