Skip to content

Conversation

@solababs
Copy link

@solababs solababs commented Sep 19, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of deeply nested schema load errors to correctly extract and display attribute labels for both list- and index-based structures; error lines are clearer and consistent.
  • Tests

    • Added unit test covering detailed error reporting when errors occur inside attributes or relationships, asserting formatted output and node lookup behavior.
  • Chores

    • Added a changelog entry noting schema load now reports errors gracefully instead of raising an exception.

@coderabbitai
Copy link

coderabbitai bot commented Sep 19, 2025

Walkthrough

The 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)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "IHS-147: Fix schema load failure exception" is a short, single-sentence summary that clearly identifies the primary change (fixing schema load failure handling) and includes the issue reference for traceability. It directly relates to the modifications in infrahub_sdk/ctl/schema.py and the added unit test without extraneous wording or emojis. This makes the title appropriate and easy for teammates to understand when scanning history.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch sb-20250919-fix-schema-load-exception-ihs-147

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b8078b4 and 5d172b9.

📒 Files selected for processing (1)
  • changelog/464.housekeeping.md (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • changelog/464.housekeeping.md
⏰ 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)
  • GitHub Check: unit-tests (3.13)
  • GitHub Check: unit-tests (3.12)
  • GitHub Check: integration-tests-latest-infrahub

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.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Sep 19, 2025

Codecov Report

❌ Patch coverage is 77.77778% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
infrahub_sdk/ctl/schema.py 77.77% 0 Missing and 2 partials ⚠️
@@             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     
Flag Coverage Δ
integration-tests 35.08% <0.00%> (-0.04%) ⬇️
python-3.10 47.90% <77.77%> (+0.02%) ⬆️
python-3.11 47.90% <77.77%> (+0.02%) ⬆️
python-3.12 47.88% <77.77%> (+0.04%) ⬆️
python-3.13 47.86% <77.77%> (+<0.01%) ⬆️
python-3.9 46.49% <77.77%> (+<0.01%) ⬆️
python-filler-3.12 25.14% <0.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
infrahub_sdk/ctl/schema.py 57.03% <77.77%> (+1.19%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

@coderabbitai coderabbitai bot left a 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.py

valid_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

📥 Commits

Reviewing files that changed from the base of the PR and between 9340fd2 and b8078b4.

📒 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.py
  • tests/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_errors function correctly handles attribute-level errors by finding the appropriate attribute name ("check_period") when loc_path[6] contains string values like "min_value" and "max_value".

Copy link
Contributor

@ogenstad ogenstad left a 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?

@cloudflare-workers-and-pages
Copy link

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

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

View logs

@solababs solababs requested a review from ogenstad September 22, 2025 11:19
@solababs solababs merged commit 840d98a into develop Sep 22, 2025
20 checks passed
@solababs solababs deleted the sb-20250919-fix-schema-load-exception-ihs-147 branch September 22, 2025 16:36
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