Skip to content

fix(python): Fix Python 3.14 compatibility with Pydantic v1 datetime parsing#12167

Merged
jsklan merged 9 commits intomainfrom
devin/1770667534-fix-python-314-pydantic-compat
Feb 10, 2026
Merged

fix(python): Fix Python 3.14 compatibility with Pydantic v1 datetime parsing#12167
jsklan merged 9 commits intomainfrom
devin/1770667534-fix-python-314-pydantic-compat

Conversation

@jsklan
Copy link
Copy Markdown
Contributor

@jsklan jsklan commented Feb 9, 2026

Description

Refs square/square-python-sdk#188, cohere-ai/cohere-python#706

SDKs generated by the Python generator emit warnings and may break on Python 3.14 because pydantic.v1.datetime_parse is incompatible with Python 3.14's new type annotation semantics (PEP 649/749). This PR removes the problematic imports and uses Pydantic V2-native alternatives instead.

Link to Devin run: https://app.devin.ai/sessions/037a40e643704fd1bd779214fa20c335
Requested by: @jsklan

Changes Made

Across all 4 pydantic_utilities.py template variants (shared/, with_pydantic_aliases/, with_pydantic_v1_on_v2/, with_pydantic_v1_on_v2/with_aliases/):

  • Replaced from pydantic.v1.datetime_parse import parse_date/parse_datetime with pydantic.TypeAdapter-based parse_date()/parse_datetime() functions that use TypeAdapter.validate_python() for date/datetime coercion
  • Wrapped all remaining pydantic.v1.* imports (ModelField, ENCODERS_BY_TYPE, get_args, get_origin, is_literal_type, is_union) in warnings.catch_warnings() to suppress the Python 3.14 UserWarning
  • Added # type: ignore[attr-defined] annotations to TypeAdapter lines for mypy compatibility when type-checking against pydantic v1 stubs
  • Updated versions.yml for python-sdk (4.55.2), pydantic (1.11.3), and fastapi (2.1.1) generators
  • Updated all corresponding seed test snapshots (368 files)

The else branch (native pydantic v1 — only used when IS_PYDANTIC_V2 is False) is intentionally left unchanged, as pydantic v1 itself does not support Python 3.14.

Human Review Checklist

  • Verify TypeAdapter.validate_python() is functionally equivalent to the old parse_date/parse_datetime for all input types (strings, datetime objects, etc.)
  • Important: In with_pydantic_v1_on_v2 variants, imports changed from pydantic.X to pydantic.v1.X (e.g., pydantic.fields.ModelFieldpydantic.v1.fields.ModelField). Confirm this is correct for the "v1 on v2" mode where pydantic v2 is installed but v1 compat layer is used.
  • Verify the TypeAdapter usage (a pydantic v2 API) works correctly in the with_pydantic_v1_on_v2 context

Testing

  • Seed snapshots updated for all affected fixtures
  • All required CI checks pass (2 non-required checks fail due to pre-existing unrelated TypeScript compilation errors in @fern-api/ir-utils)

…parsing

Replace pydantic.v1.datetime_parse imports with Pydantic V2 TypeAdapter-based
parse_date/parse_datetime implementations. Wrap remaining pydantic.v1 imports
with warning suppression to avoid Python 3.14 compatibility warnings.

Fixes: square/square-python-sdk#188, cohere-ai/cohere-python#706
Co-Authored-By: judah@buildwithfern.com <jsklan.development@gmail.com>
@devin-ai-integration
Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

devin-ai-integration bot and others added 3 commits February 9, 2026 20:31
Co-Authored-By: judah@buildwithfern.com <jsklan.development@gmail.com>
Co-Authored-By: judah@buildwithfern.com <jsklan.development@gmail.com>
…patibility

Co-Authored-By: judah@buildwithfern.com <jsklan.development@gmail.com>
@jsklan jsklan merged commit e2d473c into main Feb 10, 2026
119 checks passed
@jsklan jsklan deleted the devin/1770667534-fix-python-314-pydantic-compat branch February 10, 2026 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants