-
Notifications
You must be signed in to change notification settings - Fork 6
IHS-147: Fix schema load failure exception #555
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
IHS-147: Fix schema load failure exception #555
Conversation
WalkthroughThe change updates infrahub_sdk/ctl/schema.py to generalize how display_schema_load_errors extracts an input label for nested error locations: it inspects loc_path[6] and either iterates node[loc_type] to find an element with that attribute (when the attribute is a string) or indexes directly (when not). Error message construction is unchanged. A unit test was added to tests/unit/sdk/test_schema.py to verify attribute-level extra_forbidden errors, and a changelog entry documents the behavior change. No public signatures were modified. Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).Please share your feedback with us on this Discord post. 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 |
Codecov Report❌ Patch coverage is
@@ Coverage Diff @@
## develop #555 +/- ##
===========================================
- Coverage 75.67% 75.67% -0.01%
===========================================
Files 101 101
Lines 8959 8967 +8
Branches 1765 1768 +3
===========================================
+ Hits 6780 6786 +6
Misses 1692 1692
- Partials 487 489 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
infrahub_sdk/ctl/schema.py (1)
80-91: Harden attribute/error_data handling in infrahub_sdk/ctl/schema.pyvalid_error_path() only guarantees loc_path length — attribute can still be None/non-int and error_data can be empty or non-iterable. Add simple defensive guards.
if isinstance(attribute, str): input_label = None - for data in error_data: - if data.get(attribute) is not None: - input_label = data.get("name", None) - break + if error_data: # Guard against empty collections + for data in error_data: + if data and data.get(attribute) is not None: # Guard against None items + input_label = data.get("name", None) + break else: - input_label = error_data[attribute].get("name", None) + if isinstance(attribute, int) and 0 <= attribute < len(error_data): + input_label = error_data[attribute].get("name", None) + else: + input_label = None
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
infrahub_sdk/ctl/schema.py(1 hunks)tests/unit/sdk/test_schema.py(1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.py
📄 CodeRabbit inference engine (CLAUDE.md)
When implementing Infrahub checks, subclass InfrahubCheck and override validate(data); do not implement or rely on a check() method
Files:
infrahub_sdk/ctl/schema.pytests/unit/sdk/test_schema.py
infrahub_sdk/ctl/**/*.py
📄 CodeRabbit inference engine (CLAUDE.md)
infrahub_sdk/ctl/**/*.py: Build CLI commands with Typer
Organize and keep all CLI commands within infrahub_sdk/ctl/
Files:
infrahub_sdk/ctl/schema.py
tests/unit/**/*.py
📄 CodeRabbit inference engine (CLAUDE.md)
Place and write unit tests under tests/unit/ (isolated component tests)
Files:
tests/unit/sdk/test_schema.py
tests/**/*.py
📄 CodeRabbit inference engine (CLAUDE.md)
Use the custom pytest plugin (infrahub_sdk.pytest_plugin) fixtures for clients, configuration, and Infrahub-specific testing
Files:
tests/unit/sdk/test_schema.py
🧬 Code graph analysis (1)
tests/unit/sdk/test_schema.py (1)
infrahub_sdk/ctl/schema.py (1)
display_schema_load_errors(51-94)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
- GitHub Check: unit-tests (3.9)
- GitHub Check: unit-tests (3.11)
- GitHub Check: unit-tests (3.10)
- GitHub Check: unit-tests (3.12)
- GitHub Check: unit-tests (3.13)
- GitHub Check: integration-tests-latest-infrahub
- GitHub Check: Cloudflare Pages
🔇 Additional comments (1)
tests/unit/sdk/test_schema.py (1)
397-455: Excellent comprehensive test coverage for the new error handling logic.The test effectively validates both error cases (min_value and max_value) and confirms the expected output format. The test structure follows good practices:
- Proper mocking of dependencies
- Clear test data setup
- Specific assertions for both output content and function call counts
- Realistic error scenarios that match the production use case
The test validates that the updated
display_schema_load_errorsfunction correctly handles attribute-level errors by finding the appropriate attribute name ("check_period") whenloc_path[6]contains string values like "min_value" and "max_value".
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, can you also add an entry to towncrier indicating that #464 was fixed?
Deploying infrahub-sdk-python with
|
| Latest commit: |
5d172b9
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://9546c13b.infrahub-sdk-python.pages.dev |
| Branch Preview URL: | https://sb-20250919-fix-schema-load.infrahub-sdk-python.pages.dev |
Summary by CodeRabbit
Bug Fixes
Tests
Chores