Migration to Pydantic v2: Enable compatibility with later FastAPI versions - #5017
Conversation
Co-authored-by: marrobi <17089773+marrobi@users.noreply.github.com>
…ility layer Co-authored-by: marrobi <17089773+marrobi@users.noreply.github.com>
…grate .dict() to .model_dump() Co-authored-by: marrobi <17089773+marrobi@users.noreply.github.com>
Co-authored-by: marrobi <17089773+marrobi@users.noreply.github.com>
…n, and .dict() calls Co-authored-by: marrobi <17089773+marrobi@users.noreply.github.com>
- Remove all try/except blocks providing Pydantic v1 fallback support - Update imports to use only Pydantic v2 (TypeAdapter instead of parse_obj_as) - Clean up TypeAdapter usage throughout codebase - Fix syntax errors and whitespace issues - Maintain all existing functionality with Pydantic v2 patterns Co-authored-by: marrobi <17089773+marrobi@users.noreply.github.com>
….8.6->0.9.0 Co-authored-by: marrobi <17089773+marrobi@users.noreply.github.com>
Co-authored-by: marrobi <17089773+marrobi@users.noreply.github.com>
…paces.py Co-authored-by: marrobi <17089773+marrobi@users.noreply.github.com>
… compatability with v1
- add explicit defaults for nullable model fields - restore User-to-dict conversion for persisted resource actors - migrate remaining serialization to model_dump() - fix nested Event Grid payload serialization - restore removed resource history behavior and route imports - preserve legacy role ID, optional email, and cost date handling - update tests for Pydantic v2 response types and error messages
…tedResource classes
Good catch from copilot, we can assume that v1 and v2 will not be installed at the same time and that for imports - this is superfluous Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 121 out of 121 changed files in this pull request and generated 1 comment.
Suppressed comments (1)
templates/shared_services/certs/template_schema.json:26
- This changes the certs bundle schema, but
templates/shared_services/certs/porter.yamlremains at 0.7.11. Without a patch version bump, registries and deployments can continue resolving the old bundle despite the schema change. Bump the certs bundle version as done for the other modified templates in this PR.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 121 out of 121 changed files in this pull request and generated 2 comments.
Suppressed comments (3)
templates/shared_services/certs/template_schema.json:26
- This bundle's schema changes, but unlike the other modified bundles its
porter.yamlversion remains at 0.7.11. Bundle changes must receive a semantic version bump so the updated schema can be published and selected; increment the certs bundle version as part of this PR.
api_app/models/schemas/airlock_request.py:86 - Making
typerequired changes the public request contract: Pydantic v1 accepted payloads without this field via the empty-string default, while this model now returns HTTP 422 (as the new regression test confirms). That contradicts the PR's “zero breaking changes” claim; either preserve compatibility or explicitly treat and version this as a breaking API change.
api_app/models/schemas/airlock_request.py:100 - This also introduces a breaking request-contract change: under v1, omitting
approvalused the falsey""default and produced a rejected review, whereas the migrated endpoint now returns HTTP 422. Preserve the prior behavior or document and version the review endpoint change as breaking rather than claiming zero API changes.
Co-authored-by: ChrisChapman-gh <118748128+ChrisChapman-gh@users.noreply.github.com>
|
/test-extended |
|
🤖 pr-bot 🤖 🏃 Running extended tests: https://github.com/microsoft/AzureTRE/actions/runs/30997933316 (with refid (in response to this comment from Chris Chapman (@ChrisChapman-gh)) |
…able types so validations are clean
…ints on non-nullable properties and updating template normalization logic - app was giving 400 errors and UI would fail when submitting.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 124 out of 125 changed files in this pull request and generated no new comments.
Files not reviewed (1)
- ui/app/package-lock.json: Generated file
Suppressed comments (4)
api_app/models/domain/airlock_request.py:108
- Legacy records created when
AirlockRequestInCreate.typewas omitted contain"type": "", because the v1 default was serialized into Cosmos. Making this field optional only handles missing/null values;TypeAdapter(AirlockRequest)still rejects the persisted empty string, so list/get operations can still fail despite the stated backward-compatibility guarantee. Add a pre-validator/data migration for the empty-string representation as well (and define how such records can be used whereevent_sender.py:17requires a real type).
type: Optional[AirlockRequestType] = Field(None, title="Airlock request type")
api_app/models/schemas/airlock_request.py:86
- This changes the request contract from an optional field with a default to a required field, so existing API clients that omit
typenow receive 422. That contradicts the PR's “zero breaking changes” claim. Either preserve a compatible default/legacy handling or explicitly treat and version this as a breaking API change.
api_app/models/schemas/airlock_request.py:100 - This likewise makes
approvalrequired, whereas the v1 model accepted an omitted value and the review flow treated its falsey default as rejection. Existing clients can therefore change from a successful request to 422, contrary to the stated no-breaking-change guarantee. Preserve the previous behavior (for example, an explicitFalsedefault) or document/version the contract break.
templates/shared_services/certs/template_schema.json:31 - The certs bundle schema is modified, but
templates/shared_services/certs/porter.yamlremains at 0.7.11. Bundle changes require a semantic version increment; without it this updated schema will not be published/upgraded as a new component version. Bump the certs Porter version (and reflect it in release metadata as applicable), as done for the other changed bundles in this PR.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 124 out of 125 changed files in this pull request and generated 1 comment.
Files not reviewed (1)
- ui/app/package-lock.json: Generated file
Suppressed comments (1)
templates/shared_services/certs/template_schema.json:26
- This changes the certs bundle schema, but
templates/shared_services/certs/porter.yamlremains at0.7.11. Bundle changes must increment the Porter version so the updated schema can be published and distinguished from the existing artifact; bump it to the next patch version as done for the other modified templates in this PR.
|
/test-extended |
|
🤖 pr-bot 🤖 🏃 Running extended tests: https://github.com/microsoft/AzureTRE/actions/runs/31195708239 (with refid (in response to this comment from Chris Chapman (@ChrisChapman-gh)) |
This PR migrates the Azure TRE codebase from Pydantic v1.10.19 to v2.13.4 to enable compatibility with later versions of FastAPI that require Pydantic v2.
Overview
Later versions of FastAPI require Pydantic v2, and this migration ensures Azure TRE can upgrade FastAPI without being blocked by Pydantic version constraints.
Key Changes
🔧 Core Infrastructure Updates
api_app/requirements.txtandairlock_processor/requirements.txtnow specify Pydantic v2.13.4🏗️ Model Architecture Migration
AzureTREModelnow uses Pydantic v2ConfigDictwith v1 fallbackallow_population_by_field_name→populate_by_name@validatorto@field_validatorwith compatibility layer📦 Component Updates
parse_obj_as→TypeAdapterpatternbump-pydantictoolExample Migration Pattern
Before (Pydantic v1):
After (Pydantic v2 with v1 compatibility):
Testing & Validation
✅ Comprehensive test suite: All existing functionality preserved
✅ FastAPI compatibility: Confirmed working with FastAPI 0.115.3
✅ Component isolation: API app and airlock processor independently validated
✅ Migration tools: Used official
bump-pydantictool for schema updatesImpact
Migration Benefits
Fixes #4637.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.