Skip to content

Reduce cyclomatic complexity in generate_query_data_node#912

Merged
ogenstad merged 1 commit intoinfrahub-developfrom
pog-node-generate_query_data_node-cleanup
Apr 1, 2026
Merged

Reduce cyclomatic complexity in generate_query_data_node#912
ogenstad merged 1 commit intoinfrahub-developfrom
pog-node-generate_query_data_node-cleanup

Conversation

@ogenstad
Copy link
Copy Markdown
Contributor

@ogenstad ogenstad commented Apr 1, 2026

Why

Reduce redundant code and make the code easier to read

What changed

  • Extract cardinality dispatch into InfrahubNodeBase._build_rel_query_data
    and remove a redundant condition in the attribute alias branch, bringing
    both async and sync methods from complexity 17 to 14 (ruff C901 limit).

Summary by CodeRabbit

  • Refactor

    • Consolidated internal relationship query data generation logic to reduce code duplication in node operations.
  • Chores

    • Updated code complexity linting threshold configuration.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: 28af520
Status: ✅  Deploy successful!
Preview URL: https://ef295520.infrahub-sdk-python.pages.dev
Branch Preview URL: https://pog-node-generate-query-data.infrahub-sdk-python.pages.dev

View logs

Comment thread infrahub_sdk/node/node.py
if insert_alias:
data[attr_name]["@alias"] = f"__alias__{self._schema.kind}__{attr_name}"
elif insert_alias:
if insert_alias:
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Department of redundancy department.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 1, 2026

Codecov Report

❌ Patch coverage is 66.66667% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
infrahub_sdk/node/node.py 66.66% 3 Missing and 3 partials ⚠️
@@                 Coverage Diff                  @@
##           infrahub-develop     #912      +/-   ##
====================================================
- Coverage             81.04%   81.03%   -0.01%     
====================================================
  Files                   121      121              
  Lines                 10644    10642       -2     
  Branches               1586     1583       -3     
====================================================
- Hits                   8626     8624       -2     
+ Misses                 1502     1501       -1     
- Partials                516      517       +1     
Flag Coverage Δ
integration-tests 40.79% <55.55%> (-0.03%) ⬇️
python-3.10 52.39% <55.55%> (-0.03%) ⬇️
python-3.11 52.39% <55.55%> (-0.01%) ⬇️
python-3.12 52.37% <55.55%> (-0.03%) ⬇️
python-3.13 52.39% <55.55%> (-0.01%) ⬇️
python-3.14 54.10% <55.55%> (-0.01%) ⬇️
python-filler-3.12 24.06% <11.11%> (+0.02%) ⬆️

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

Files with missing lines Coverage Δ
infrahub_sdk/node/node.py 85.91% <66.66%> (-0.03%) ⬇️

... and 4 files with indirect coverage changes

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

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 1, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 01108ddf-8207-400e-b27d-063e4817c6d0

📥 Commits

Reviewing files that changed from the base of the PR and between 4704159 and 28af520.

📒 Files selected for processing (2)
  • infrahub_sdk/node/node.py
  • pyproject.toml

Walkthrough

Refactored relationship query-data generation in the node module by extracting a new static helper method _build_rel_query_data() in InfrahubNodeBase that handles both cardinality types and hierarchy-specific GraphQL fragments. Updated both async and sync implementations of generate_query_data_node() to use this centralized helper instead of duplicated inline construction. Removed redundant conditional nesting in attribute alias insertion. Additionally, tightened Ruff's McCabe complexity threshold from 17 to 14 in project configuration.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: reducing cyclomatic complexity in the generate_query_data_node method, which is the core focus of this PR.
Description check ✅ Passed The description covers the key sections (Why and What changed) but lacks important context like behavioral impact, testing instructions, and deployment notes that would help reviewers understand the full scope.

✏️ 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.

❤️ Share

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

@ogenstad ogenstad marked this pull request as ready for review April 1, 2026 08:17
@ogenstad ogenstad requested a review from a team as a code owner April 1, 2026 08:17
@ogenstad ogenstad merged commit fff91da into infrahub-develop Apr 1, 2026
21 checks passed
@ogenstad ogenstad deleted the pog-node-generate_query_data_node-cleanup branch April 1, 2026 11:12
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