Skip to content

Upgrade to Pydantic v2#7

Merged
dannyshaw merged 2 commits into
masterfrom
danny/pydantic2
Mar 11, 2026
Merged

Upgrade to Pydantic v2#7
dannyshaw merged 2 commits into
masterfrom
danny/pydantic2

Conversation

@dannyshaw
Copy link
Copy Markdown
Contributor

Motivation and Context

wistiapy currently pins pydantic>=1.8.2,<2.0.0, which blocks any project using Pydantic v2 from depending on this library. Since Pydantic v1 is end-of-life and our main application (and many of our other dependencies) have moved to Pydantic v2, this upgrade unblocks that constraint.

Description

Migrates the wistiapy webhook models from Pydantic v1 APIs to Pydantic v2 equivalents. The changes are minimal and targeted:

Dependency constraint (pyproject.toml):

  • Changed pydantic>=1.8.2,<2.0.0 to pydantic>=2.0.0 - drops v1 support entirely in favour of v2.

Model fixes (wistia/webhooks.py):

  • MediaInfo.duration: Optional[float] changed to Optional[float] = None - Pydantic v2 requires Optional fields to have an explicit default value.
  • EventDelivery.parse_raw(event_data) replaced with EventDelivery.model_validate_json(event_data) - parse_raw was removed in Pydantic v2.

Test updates (tests/test_webhooks.py):

  • MediaUpdatedEvent.parse_obj(...) replaced with MediaUpdatedEvent.model_validate(...) - parse_obj was removed in Pydantic v2.

Design Review

  • I can justify not having these changes signed off by a designer.

Documentation

  • I can justify not updating or adding root domain documentation.

This is a dependency version bump with no API surface changes for consumers of the library.

Automated Testing

  • I have added or updated tests to cover my changes.

All 16 existing tests pass on Pydantic v2 with the updated API calls.

Sensitive Data Masking

  • I can justify that no masking is required (this PR does not render or modify sensitive text).

How Has This Been Manually Tested?

  • I feel I can justify not deploying to a dev stack

uv run python -m pytest tests/ -v - all 16 tests pass.

Backwards Compatibility

  • This is a breaking change for anyone running Pydantic v1 - the <2.0.0 upper bound is removed and replaced with >=2.0.0. Any consumer of this library must be on Pydantic v2.
  • No changes to the public API of wistiapy itself (parse_webhook_event_delivery, model classes, validate_webhook_signature etc. all remain identical).
  • Version bumped to 0.1.0 to signal the breaking dependency change. Will need a PyPI release once merged.

dannyshaw and others added 2 commits March 11, 2026 10:53
- Update pydantic dependency constraint from <2.0.0 to >=2.0.0
- parse_raw() -> model_validate_json()
- parse_obj() -> model_validate()
- Add default=None to Optional duration field on MediaInfo

All 16 tests pass with Pydantic 2.12.5.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@dannyshaw dannyshaw merged commit 72a8a98 into master Mar 11, 2026
6 checks passed
@dannyshaw dannyshaw deleted the danny/pydantic2 branch March 11, 2026 05:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants