-
Notifications
You must be signed in to change notification settings - Fork 1
Simplify Lab Schema Validation #146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…ove redundant checks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR simplifies schema validation logic by migrating from Pydantic's field_validator to model_validator with mode "after", enabling access to all validated class attributes and eliminating redundant null checks. The change centralizes validation logic through reusable mixin classes that can be inherited across different schema types.
Key changes:
- Replaced individual field validators with model validators that access validated class attributes directly
- Created validation mixin classes (
VPCCreateValidationMixin,SubnetCreateValidationMixin,RangeCreateValidationMixin) to eliminate code duplication - Removed null/existence checks for fields that are guaranteed to be validated by Pydantic
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| vpc_schemas.py | Introduces VPCCreateValidationMixin with model validators and removes duplicate validation logic from both blueprint and deployed VPC creation schemas |
| subnet_schemas.py | Creates SubnetCreateValidationMixin with model validators and refactors blueprint and deployed subnet schemas to use the mixin |
| range_schemas.py | Adds RangeCreateValidationMixin with model validators for VPC validation and removes duplicate validation code from range creation schemas |
| host_schemas.py | Converts field validator to model validator for size validation, removing the need for null checks on the OS field |
| raise ValueError(msg) | ||
|
|
||
| msg = f"All subnet in VPC: {vpc_name} must have unique names." | ||
| msg = f"All subnet in VPC: {self.name} must have unique names." |
Copilot
AI
Jul 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Grammar error: 'All subnet' should be 'All subnets' (missing 's' for plural).
| msg = f"All subnet in VPC: {self.name} must have unique names." | |
| msg = f"All subnets in VPC: {self.name} must have unique names." |
|
|
||
| vpc_cidrs = [vpc.cidr for vpc in self.vpcs] | ||
| if not mutually_exclusive_networks_v4(vpc_cidrs): | ||
| msg = "All VPCs in the range must be mutually exclusive (not overlap)." |
Copilot
AI
Jul 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The error message differs from the original 'All VPCs in range should be mutually exclusive (not overlap).' Consider maintaining consistency with the original wording unless the change is intentional.
| msg = "All VPCs in the range must be mutually exclusive (not overlap)." | |
| msg = "All VPCs in range should be mutually exclusive (not overlap)." |
Nareshp1
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Checklist
Description
This PR simplifies validation logic for the
Range,VPC,Subnet, andHostschemas by leveraging Pydantic'smodel_validatorthat provides access to class attributes after each field has been individually validated. This allows for the removal of all theif not fieldchecks.Additionally, this PR deduplicates the validation logic by centralizing the validation functions in a
ValidationSchemaclass that can be inheritedFixes: #107