feat: IHS-190 (part of IFC-2162) Add namespace restriction parameter to generic schemas#807
feat: IHS-190 (part of IFC-2162) Add namespace restriction parameter to generic schemas#807polmichel wants to merge 3 commits intoinfrahub-developfrom
Conversation
…ed_namespaces but also missing fields IHS-190
…rough infrahubctl command layer. Infrahub API is mocked IHS-190
…nvalid namespace is loaded from SDK methods. Infrahub API is mocked IHS-190
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## infrahub-develop #807 +/- ##
====================================================
- Coverage 80.33% 80.33% -0.01%
====================================================
Files 115 115
Lines 9865 9869 +4
Branches 1504 1504
====================================================
+ Hits 7925 7928 +3
- Misses 1419 1420 +1
Partials 521 521
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 1 file with indirect coverage changes 🚀 New features to boost your workflow:
|
|
Small comment on this PR. It should target the |
WalkthroughThis pull request extends the generic schema API with support for namespace restrictions on generic types. Two new optional fields are added to the GenericSchemaAPI class: 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@infrahub_sdk/schema/main.py`:
- Around line 292-294: GenericSchema is missing the hierarchical and
restricted_namespaces attributes present in GenericSchemaAPI, causing those
values (e.g., restricted_namespaces from valid_generic_schema.json) to be
dropped when parsed via SchemaRoot; add the two fields to GenericSchema by
declaring hierarchical: bool | None = None and restricted_namespaces: list[str]
| None = None on the GenericSchema dataclass/model so it matches
GenericSchemaAPI and preserves round-trip parsing of those properties.
🧹 Nitpick comments (2)
tests/unit/sdk/test_schema.py (2)
516-537: Variableerror_messageis shadowed on Line 536.
error_messageis first defined on Line 516 as the mock response string, then reassigned on Line 536 to the extracted value from the response. This shadowing is confusing — use a distinct name for one of them.Suggested fix
- error_message = response.errors["errors"][0]["message"] - assert re.search(r"(?s)restricted namespaces(?=.*Dog)(?=.*Cat)", error_message) + actual_error = response.errors["errors"][0]["message"] + assert re.search(r"(?s)restricted namespaces(?=.*Dog)(?=.*Cat)", actual_error)
488-538: Test only covers the async path; consider adding sync coverage.Existing tests in this file consistently parametrize over
["standard", "sync"]client types (e.g., Lines 47, 66, 93). This test only exercisesInfrahubClient(async). Consider adding a sync variant usingInfrahubClientSync.schema.loadfor parity, consistent with the existing pattern in this file. As per coding guidelines,infrahub_sdk/**/*.py: Follow async/sync dual pattern for new features in the Python SDK.
To understand the global feature, see this PR: opsmill/infrahub#8319
This PR is about updating
infrahub_sdk.schema.main.GenericSchemaAPIwith the new generic schema parameter "restricted_namespaces".Goal
See opsmill/infrahub#8319
Non-goals
Added another missing attribute to
infrahub_sdk.schema.main.GenericSchemaAPI: hierarchical. This attribute was already into the internal Infrahub generic schema model.What changed
Generic schemas into SDK API.
How-to review
This PR is quite small: commit by commit, in the chronological order.
How to test
Automated back-end tests:
uv run pytest tests/unit/ctl/test_schema_app.py tests/unit/sdk/test_schema.pyApplication testing scenarios:
Impact & rollout
Deployment notes: safe to deploy
Closes IHS-190
Summary by CodeRabbit
New Features
Tests