Skip to content

refactor(sdk): type group members access via _get_relationship_many - #1227

Open
saltas888 wants to merge 1 commit into
developfrom
pha/INBOX-28
Open

refactor(sdk): type group members access via _get_relationship_many#1227
saltas888 wants to merge 1 commit into
developfrom
pha/INBOX-28

Conversation

@saltas888

@saltas888 saltas888 commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Why

infrahub_sdk/query_groups.py had two existing_group.members.peer_ids accesses, each silenced with # type: ignore[union-attr] because .members is typed as a union that includes None.

PR #412 introduced _get_relationship_many(name="members") specifically to type this access, and applied it at the two .peers call sites (L108 / L206) — but the two .peer_ids sites (L178 / L270) were left behind with their suppressions. This finishes that migration.

Non-goals: no change to grouping behaviour, no public API change, no new accessor added (none was needed — see below).

Jira: INBOX-28
Source: #412 (comment)

What changed

Behavioral changes: none. This is a like-for-like typing substitution.

  • Routed both existing_group.members.peer_ids sites through existing_group._get_relationship_many(name="members").peer_ids.
  • Deleted both # type: ignore[union-attr] suppressions — the last two in this module.

Implementation note: the card left open whether a peer_ids helper would need adding. It does not — peer_ids is defined on RelationshipManagerBase (infrahub_sdk/node/relationship.py:61), so it resolves for both the async RelationshipManager and the sync RelationshipManagerSync that _get_relationship_many returns. Both the async (InfrahubGroupContext) and sync (InfrahubGroupContextSync) twins get the identical treatment, so the twins stay in sync.

What stayed the same: no schema changes, no API contract changes, no dependency changes, no CI changes, no generated files. The diff is 2 files: one source file and one changelog fragment.

How to review

The whole change is 6 lines in one file. The only thing worth checking is that peer_ids is genuinely available on the base class (linked above) so the async and sync paths are both really typed rather than newly ignored.

How to test

# The card's stated verifier — project-wide, as CI runs it:
uv run mypy --show-error-codes infrahub_sdk/

# Lint:
uv run ruff check . && uv run ruff format --check .

# Tests covering the changed module:
uv run pytest tests/unit/sdk/test_group_context.py

Results on this branch:

Check Result
mypy --show-error-codes infrahub_sdk/ Success: no issues found in 152 source files
ruff check . All checks passed
ruff format --check . 332 files already formatted
pytest tests/unit/sdk/test_group_context.py 11 passed
pytest tests/unit/sdk/ 1064 passed, 3 failed

The 3 failures are in tests/unit/sdk/test_schema.py (test_display_schema_load_errors_details_*) and are pre-existing and unrelated — they assert on plain strings while Rich emits ANSI colour codes in this environment. Verified by stashing this change and re-running on the clean base commit: the same 3 fail identically there.

ty check . reports 48 unresolved-import diagnostics in this environment only, because the tests dependency group could not be installed locally (ruamel-yaml-clib has no cp314 wheel and needs Python.h, which isn't present on this machine). None of them are in query_groups.py. CI installs the full group, so this is a local environment artifact.

Impact & rollout

  • Backward compatibility: no breaking changes — internal typing only.
  • Performance: no measurable change; the accessor is a dict lookup on already-fetched relationship data.
  • Config/env changes: none.
  • Deployment notes: safe to deploy.

Checklist

  • Tests added/updated — not applicable; this is a typing-only change with no new behaviour to cover, and mypy is the verifier. Existing test_group_context.py coverage exercises both changed code paths.
  • Changelog entry added (changelog/+query-groups-typed-members-accessor.housekeeping.md)
  • External docs updated (if user-facing or ops-facing change) — n/a, not user-facing
  • Internal .md docs updated — n/a, no convention change

🤖 Generated with Claude Code


Summary by cubic

Use the typed existing_group._get_relationship_many(name="members").peer_ids in infrahub_sdk/query_groups.py to replace the last existing_group.members.peer_ids usages, removing two # type: ignore[union-attr] suppressions. No behavior change; fulfills INBOX-28.

Written for commit d36aa57. Summary will update on new commits.

Review in cubic

The two `existing_group.members.peer_ids` sites in query_groups.py each
carried a `# type: ignore[union-attr]` because `.members` is typed as a
union that includes `None`. PR #412 introduced
`_get_relationship_many(name="members")` precisely to type this access and
applied it at the two `.peers` call sites, but the `.peer_ids` sites were
left behind.

Route both through the typed accessor and drop the suppressions. `peer_ids`
is defined on `RelationshipManagerBase`, so it resolves for both the async
`RelationshipManager` and the sync `RelationshipManagerSync` — a like-for-like
substitution with no behavioural change.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@saltas888
saltas888 requested a review from a team as a code owner August 6, 2026 11:10
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: d36aa57
Status: ✅  Deploy successful!
Preview URL: https://c4638dad.infrahub-sdk-python.pages.dev
Branch Preview URL: https://pha-inbox-28.infrahub-sdk-python.pages.dev

View logs

@codecov

codecov Bot commented Aug 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@             Coverage Diff             @@
##           develop    #1227      +/-   ##
===========================================
- Coverage    85.21%   82.97%   -2.24%     
===========================================
  Files          146      141       -5     
  Lines        15605    12614    -2991     
  Branches      2631     1909     -722     
===========================================
- Hits         13298    10467    -2831     
+ Misses        1642     1577      -65     
+ Partials       665      570      -95     
Flag Coverage Δ
integration-tests 40.07% <100.00%> (-1.48%) ⬇️
python-3.10 57.40% <0.00%> (-0.76%) ⬇️
python-3.11 57.42% <0.00%> (-0.75%) ⬇️
python-3.12 57.40% <0.00%> (-0.75%) ⬇️
python-3.13 57.42% <0.00%> (-0.75%) ⬇️
python-3.14 57.41% <0.00%> (-0.75%) ⬇️
python-filler-3.12 21.78% <0.00%> (-2.80%) ⬇️

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

Files with missing lines Coverage Δ
infrahub_sdk/query_groups.py 84.55% <100.00%> (ø)

... and 30 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Re-trigger cubic

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