Jump to solution
Verify

The Fix

pip install pydantic==2.9.2

Based on closed pydantic/pydantic issue #10407 · 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
@@ -1650,7 +1650,7 @@ def validate_str_is_valid_iana_tz(value: Any, /) -> ZoneInfo: try: return ZoneInfo(value) - except (ZoneInfoNotFoundError, ValueError): + except (ZoneInfoNotFoundError, ValueError, TypeError): raise PydanticCustomError('zoneinfo_str', 'invalid timezone: {value}', {'value': value})
repro.py
from zoneinfo import ZoneInfo from datetime import timezone from pydantic import TypeAdapter, ConfigDict ta = TypeAdapter(ZoneInfo | timezone, config=ConfigDict(arbitrary_types_allowed=True)) assert ta.validate_python(timezone.utc) is timezone.utc
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.9.2\nWhen NOT to use: Do not use this fix if the application relies on specific timezone validation behavior.\n\n

Why This Fix Works in Production

  • Trigger: *** TypeError: expected str, bytes or os.PathLike object, not timezone
  • Mechanism: TypeError occurs when validating timezone/ZoneInfo union due to invalid type handling
  • Why the fix works: Fixes a TypeError when validating timezone/ZoneInfo union in Pydantic. (first fixed release: 2.9.2).
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).
  • TypeError occurs when validating timezone/ZoneInfo union due to invalid type handling
  • Surfaces as: *** TypeError: expected str, bytes or os.PathLike object, not timezone

Proof / Evidence

Discussion

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

“Thanks for the report! I've opened a PR with a fix, should roll out early next week.”
@sydney-runkle · 2024-09-13 · source

Failure Signature (Search String)

  • *** TypeError: expected str, bytes or os.PathLike object, not timezone

Error Message

Stack trace
error.txt
Error Message ------------- *** TypeError: expected str, bytes or os.PathLike object, not timezone Traceback (most recent call last): File "/Users/kkirsche/Library/Caches/pypoetry/virtualenvs/projectname-g3Hahb8t-py3.12/lib/python3.12/site-packages/pydantic/main.py", line 209, in __init__ validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/kkirsche/Library/Caches/pypoetry/virtualenvs/projectname-g3Hahb8t-py3.12/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 1659, in validate_str_is_valid_iana_tz return ZoneInfo(value) ^^^^^^^^^^^^^^^ File "/Users/kkirsche/.asdf/installs/python/3.12.6/lib/python3.12/zoneinfo/_tzpath.py", line 73, in find_tzfile _validate_tzfile_path(key) File "/Users/kkirsche/.asdf/installs/python/3.12.6/lib/python3.12/zoneinfo/_tzpath.py", line 86, in _validate_tzfile_path if os.path.isabs(path): ^^^^^^^^^^^^^^^^^^^ File "<frozen posixpath>", line 62, in isabs

Minimal Reproduction

repro.py
from zoneinfo import ZoneInfo from datetime import timezone from pydantic import TypeAdapter, ConfigDict ta = TypeAdapter(ZoneInfo | timezone, config=ConfigDict(arbitrary_types_allowed=True)) assert ta.validate_python(timezone.utc) is timezone.utc

Environment

  • Python: 3.12
  • Pydantic: 2

What Broke

Application fails to validate timezone data, causing runtime errors in production.

Why It Broke

TypeError occurs when validating timezone/ZoneInfo union due to invalid type handling

Fix Options (Details)

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

pip install pydantic==2.9.2

When NOT to use: Do not use this fix if the application relies on specific timezone validation behavior.

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/10408

First fixed release: 2.9.2

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 this fix if the application relies on specific timezone validation behavior.

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

Related Issues

No related fixes found.

Sources

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