EDM-5201: handle pydantic ValidationError in api_module get()/list() - #66
Merged
Merged
Conversation
The Flight Control client SDK deserializes API responses into pydantic models. A device with a mount-only application volume (no `image`) makes the SDK's ApplicationVolume model raise a pydantic ValidationError, which is not a subclass of ApiException. FlightctlAPIModule.get()/list() — the shared chokepoint behind flightctl_resource_info, device/fleet modules, and approvals — only caught ApiException, so the error propagated as an unhandled traceback. Apply the same raw-JSON fallback already used by the inventory plugin (EDM-4980): on a pydantic ValidationError, retry against the SDK's *_without_preload_content endpoints and wrap the payload so downstream consumers keep working. Extract the pydantic-detection helper into a shared module_utils/sdk_utils.py used by both the inventory plugin and api_module. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Add an end-to-end test that provokes a genuine pydantic ValidationError from the SDK's ApplicationVolume model (mount-only volume without `image`) and asserts FlightctlAPIModule.get() recovers via the raw-JSON fallback. This proves the ticket premise against the real SDK rather than a stand-in error. The test skips if the SDK model shape changes. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
EfratIfergan
marked this pull request as ready for review
August 23, 2026 08:17
SiddarthR56
approved these changes
Aug 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The Flight Control client SDK deserializes API responses into pydantic models. When a device has a mount-only application volume (a volume with no
imagefield), the SDK'sApplicationVolumemodel raises a pydanticValidationErrorduring deserialization — which is not a subclass of the SDK'sApiException.FlightctlAPIModule.get()andlist()(plugins/module_utils/api_module.py) — the shared chokepoint behindflightctl_resource_info, the device/fleet modules, and approvals — only catchApiException/NotFoundException. The pydantic error therefore propagated unhandled, crashing the module with a raw Python traceback instead of a clean Ansible failure or a successful read.EDM-4980 (#63) fixed this same root cause for the inventory plugin only; this change applies the equivalent fix to the shared API module.
Change
plugins/module_utils/sdk_utils.py— extracts the pydantic-detection helper into a shared location asis_pydantic_validation_error(), plus a smallraw_response_to_dict()helper. The inventory plugin now imports the shared helper (keeping its_is_pydantic_validation_errorname as an alias), removing the duplicate definition.plugins/module_utils/api_module.py—get()andlist()now catch a pydanticValidationError, warn, and retry against the SDK's*_without_preload_contentraw endpoints, returning lightweightRawResource/RawListResponsewrappers that expose the sameto_dict()/items/metadata/summaryinterface downstream consumers (get_one_or_many(),ListResult.to_dict()) already expect. Non-pydantic exceptions are re-raised unchanged; a failure of the raw retry surfaces a cleanFlightctlApiException.Tests
tests/unit/plugins/module_utils/test_sdk_utils.py(new) — unit tests for the shared helpers.tests/unit/plugins/module_utils/test_api_module.py— fallback tests covering the exact ticket scenario (device get with a mount-only volume), the rendered-device path,list()with items/metadata/summary, end-to-endget_one_or_many()serialization, non-pydantic re-raise, and raw-retry failure →FlightctlApiException.Full unit suite: 230 passed (inventory suite unaffected: 80 passed).
Reproduction / Verification
image).flightctl_resource_info: kind=Deviceagainst it.FlightctlApiException.🤖 Generated with Claude Code