Skip to content

Use RelationshipCardinality enum in favor of a string#913

Merged
ogenstad merged 1 commit intoinfrahub-developfrom
pog-use-relationship-cardinality-enum
Apr 1, 2026
Merged

Use RelationshipCardinality enum in favor of a string#913
ogenstad merged 1 commit intoinfrahub-developfrom
pog-use-relationship-cardinality-enum

Conversation

@ogenstad
Copy link
Copy Markdown
Contributor

@ogenstad ogenstad commented Apr 1, 2026

Why

We have an enum for RelationshipCardinality but in a number of places we were instead using a hard coded string, this is a slight cleanup to ensure that we have the correct types throughout the code.

What changed

  • Update static strings and replace with the RelationshipCardinality enum

Summary by CodeRabbit

  • Refactor
    • Enhanced internal code quality and type safety in relationship handling modules through improved consistency in cardinality checks across multiple components.

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

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: 35cf000
Status: ✅  Deploy successful!
Preview URL: https://6633528d.infrahub-sdk-python.pages.dev
Branch Preview URL: https://pog-use-relationship-cardina.infrahub-sdk-python.pages.dev

View logs

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 1, 2026

Walkthrough

This pull request refactors cardinality comparison logic across multiple modules in the infrahub SDK. String-based cardinality checks using literals like "one" and "many" are replaced with enum-based comparisons using RelationshipCardinality.ONE and RelationshipCardinality.MANY. Changes are applied consistently across node initialization, query building, relationship filtering, payload generation, and code generation routines. The control flow and logic remain unchanged; only the comparison mechanism is updated to use enumerated constants instead of string literals.

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description covers the Why (type consistency) and What changed (enum replacement) sections, but lacks implementation details, testing instructions, and impact assessment required by the template. Add 'What stayed the same' section, 'How to review' guidance, testing instructions with specific commands, and backward compatibility/impact statement to align with template expectations.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: replacing string-based cardinality checks with RelationshipCardinality enum comparisons across multiple files.

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

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 1, 2026

Codecov Report

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

Files with missing lines Patch % Lines
infrahub_sdk/spec/object.py 66.66% 0 Missing and 3 partials ⚠️
infrahub_sdk/schema/__init__.py 0.00% 2 Missing ⚠️
infrahub_sdk/node/node.py 75.00% 0 Missing and 1 partial ⚠️
@@                Coverage Diff                @@
##           infrahub-develop     #913   +/-   ##
=================================================
  Coverage             81.03%   81.03%           
=================================================
  Files                   121      121           
  Lines                 10642    10643    +1     
  Branches               1583     1583           
=================================================
+ Hits                   8624     8625    +1     
  Misses                 1501     1501           
  Partials                517      517           
Flag Coverage Δ
integration-tests 40.78% <63.15%> (-0.01%) ⬇️
python-3.10 52.38% <42.10%> (-0.02%) ⬇️
python-3.11 52.38% <42.10%> (-0.02%) ⬇️
python-3.12 52.38% <42.10%> (+<0.01%) ⬆️
python-3.13 52.38% <42.10%> (-0.02%) ⬇️
python-3.14 54.10% <42.10%> (+<0.01%) ⬆️
python-filler-3.12 24.06% <0.00%> (-0.01%) ⬇️

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

Files with missing lines Coverage Δ
infrahub_sdk/protocols_generator/generator.py 95.00% <100.00%> (ø)
infrahub_sdk/transfer/importer/json.py 76.92% <100.00%> (+0.16%) ⬆️
infrahub_sdk/node/node.py 85.91% <75.00%> (ø)
infrahub_sdk/schema/__init__.py 73.42% <0.00%> (ø)
infrahub_sdk/spec/object.py 85.24% <66.66%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ogenstad ogenstad marked this pull request as ready for review April 1, 2026 13:02
@ogenstad ogenstad requested a review from a team as a code owner April 1, 2026 13:02
Copy link
Copy Markdown

@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.

🧹 Nitpick comments (1)
infrahub_sdk/transfer/importer/json.py (1)

134-142: Update exporter to use enum-based cardinality checks for consistency.

The importer correctly migrated cardinality comparisons to use RelationshipCardinality.MANY enum (lines 134, 139), but the exporter (infrahub_sdk/transfer/exporter/json.py, lines 46, 53) still uses string literals ("many"). Align the exporter with the importer's approach by replacing string comparisons with enum comparisons for consistency and type safety across the transfer module.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@infrahub_sdk/transfer/importer/json.py` around lines 134 - 142, The exporter
still compares cardinality using string literals ("many"); change those
comparisons to use the enum value RelationshipCardinality.MANY (e.g., replace
occurrences like card == "many" or card != "many" with card ==
RelationshipCardinality.MANY / card != RelationshipCardinality.MANY) in the JSON
exporter logic that mirrors the importer (check locations around the previous
string checks in infrahub_sdk/transfer/exporter/json.py), and ensure
RelationshipCardinality is imported/accessible in that module so the enum-based
comparisons compile and mirror the importer behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@infrahub_sdk/transfer/importer/json.py`:
- Around line 134-142: The exporter still compares cardinality using string
literals ("many"); change those comparisons to use the enum value
RelationshipCardinality.MANY (e.g., replace occurrences like card == "many" or
card != "many" with card == RelationshipCardinality.MANY / card !=
RelationshipCardinality.MANY) in the JSON exporter logic that mirrors the
importer (check locations around the previous string checks in
infrahub_sdk/transfer/exporter/json.py), and ensure RelationshipCardinality is
imported/accessible in that module so the enum-based comparisons compile and
mirror the importer behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4deab71c-2f62-4d12-9c05-94cc9c84158d

📥 Commits

Reviewing files that changed from the base of the PR and between fff91da and 35cf000.

📒 Files selected for processing (5)
  • infrahub_sdk/node/node.py
  • infrahub_sdk/protocols_generator/generator.py
  • infrahub_sdk/schema/__init__.py
  • infrahub_sdk/spec/object.py
  • infrahub_sdk/transfer/importer/json.py

Copy link
Copy Markdown

@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.

🧹 Nitpick comments (1)
infrahub_sdk/transfer/importer/json.py (1)

134-142: Update exporter to use enum-based cardinality checks for consistency.

The importer correctly migrated cardinality comparisons to use RelationshipCardinality.MANY enum (lines 134, 139), but the exporter (infrahub_sdk/transfer/exporter/json.py, lines 46, 53) still uses string literals ("many"). Align the exporter with the importer's approach by replacing string comparisons with enum comparisons for consistency and type safety across the transfer module.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@infrahub_sdk/transfer/importer/json.py` around lines 134 - 142, The exporter
still compares cardinality using string literals ("many"); change those
comparisons to use the enum value RelationshipCardinality.MANY (e.g., replace
occurrences like card == "many" or card != "many" with card ==
RelationshipCardinality.MANY / card != RelationshipCardinality.MANY) in the JSON
exporter logic that mirrors the importer (check locations around the previous
string checks in infrahub_sdk/transfer/exporter/json.py), and ensure
RelationshipCardinality is imported/accessible in that module so the enum-based
comparisons compile and mirror the importer behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@infrahub_sdk/transfer/importer/json.py`:
- Around line 134-142: The exporter still compares cardinality using string
literals ("many"); change those comparisons to use the enum value
RelationshipCardinality.MANY (e.g., replace occurrences like card == "many" or
card != "many" with card == RelationshipCardinality.MANY / card !=
RelationshipCardinality.MANY) in the JSON exporter logic that mirrors the
importer (check locations around the previous string checks in
infrahub_sdk/transfer/exporter/json.py), and ensure RelationshipCardinality is
imported/accessible in that module so the enum-based comparisons compile and
mirror the importer behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4deab71c-2f62-4d12-9c05-94cc9c84158d

📥 Commits

Reviewing files that changed from the base of the PR and between fff91da and 35cf000.

📒 Files selected for processing (5)
  • infrahub_sdk/node/node.py
  • infrahub_sdk/protocols_generator/generator.py
  • infrahub_sdk/schema/__init__.py
  • infrahub_sdk/spec/object.py
  • infrahub_sdk/transfer/importer/json.py

@ogenstad ogenstad merged commit fc0bb09 into infrahub-develop Apr 1, 2026
21 checks passed
@ogenstad ogenstad deleted the pog-use-relationship-cardinality-enum branch April 1, 2026 14:11
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