Skip to content

Conversation

@LucasG0
Copy link
Contributor

@LucasG0 LucasG0 commented Sep 24, 2025

Add use_default_value in order to specify when we want of a field to use the default value instead of potentially reusing the value of an existing matching input field.

Summary by CodeRabbit

  • New Features

    • Added a boolean option to allow using a default value in conversion inputs.
  • Bug Fixes

    • Validation now enforces exactly one of: source field, inline data, or the default-value option, preventing conflicting or missing configurations.
  • Style

    • Improved validation error messages by wrapping field names in backticks for clearer readability and easier troubleshooting.

@coderabbitai
Copy link

coderabbitai bot commented Sep 24, 2025

Walkthrough

Changes in infrahub_sdk/convert_object_type.py: the error message in ConversionFieldValue.check_only_one_field now wraps field names in backticks. ConversionFieldInput gains a new public boolean field use_default_value (default False) and its docstring was updated. Validation in ConversionFieldInput.check_only_one_field now enforces that exactly one of source_field, data, or use_default_value is set. No other method signatures were changed.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title Check ❓ Inconclusive The title “Add to object conversion input” is related to the change but omits the key information of what is being added, making it too vague to convey the main update. The pull request introduces a new use_default_value field, yet the title does not include that name, so a reader cannot grasp the primary change at a glance. Please update the title to explicitly include the new field name, for example “Add use_default_value to object conversion input,” so it clearly summarizes the main change.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch lgu-obj-conv-use-default-value

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.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Sep 24, 2025

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5498204
Status: ✅  Deploy successful!
Preview URL: https://f222ad5a.infrahub-sdk-python.pages.dev
Branch Preview URL: https://lgu-obj-conv-use-default-val.infrahub-sdk-python.pages.dev

View logs

@LucasG0 LucasG0 marked this pull request as ready for review September 24, 2025 14:15
@LucasG0 LucasG0 requested a review from a team September 24, 2025 14:15
@codecov
Copy link

codecov bot commented Sep 24, 2025

Codecov Report

❌ Patch coverage is 40.00000% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
infrahub_sdk/convert_object_type.py 40.00% 2 Missing and 1 partial ⚠️
@@             Coverage Diff             @@
##           develop     #558      +/-   ##
===========================================
+ Coverage    75.73%   75.76%   +0.02%     
===========================================
  Files          101      101              
  Lines         8969     8969              
  Branches      1769     1768       -1     
===========================================
+ Hits          6793     6795       +2     
+ Misses        1689     1688       -1     
+ Partials       487      486       -1     
Flag Coverage Δ
integration-tests 35.08% <20.00%> (+0.01%) ⬆️
python-3.10 47.95% <0.00%> (-0.03%) ⬇️
python-3.11 47.95% <0.00%> (-0.03%) ⬇️
python-3.12 47.93% <0.00%> (ø)
python-3.13 47.95% <0.00%> (ø)
python-3.9 46.58% <0.00%> (ø)
python-filler-3.12 25.15% <20.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/convert_object_type.py 84.00% <40.00%> (+8.00%) ⬆️
🚀 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: 1

🧹 Nitpick comments (2)
infrahub_sdk/convert_object_type.py (2)

53-59: Prefer Optional[bool] for use_default_value to avoid serializing False by default

Model dumps that only exclude None will otherwise include "use_default_value": False unnecessarily. Making it Optional avoids noisy payloads and aligns with the “exactly one set” pattern used by other fields.

Apply this diff:

-    use_default_value: bool = False
+    use_default_value: bool | None = None
@@
-        fields_set = [self.source_field is not None, self.data is not None, self.use_default_value is True]
+        fields_set = [self.source_field is not None, self.data is not None, self.use_default_value is True]

Note: No change needed in the validator logic; is True still works as intended.


57-60: Guard against empty/whitespace-only source_field

Treating "" as “set” will pass validation but is likely invalid upstream. Reject early.

Apply this diff:

     @model_validator(mode="after")
     def check_only_one_field(self) -> ConversionFieldInput:
+        if self.source_field is not None and not self.source_field.strip():
+            raise ValueError("`source_field`, if provided, must be a non-empty string")
         fields_set = [self.source_field is not None, self.data is not None, self.use_default_value is True]
         if sum(fields_set) != 1:
             raise ValueError("Exactly one of `source_field`, `data` or `use_default_value` must be set")
         return self
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 840d98a and 27c4e81.

📒 Files selected for processing (1)
  • infrahub_sdk/convert_object_type.py (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.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/convert_object_type.py
⏰ 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: integration-tests-latest-infrahub
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (2)
infrahub_sdk/convert_object_type.py (2)

39-40: Error message clarity: LGTM

Backticks improve readability/consistency across validation errors.


53-59: Confirm backend schema supports use_default_value

Please verify the GraphQL mutation/validation layer accepts the new use_default_value key in fields_mapping to prevent server-side rejections.

Use `source_field` to reuse the value of the corresponding field of the object being converted.
Use `data` to specify the new value for the field.
Use `use_default_value` to set the destination field to its schema default.
Only one of `source_field` or `data` can be specified.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Only one of `source_field` or `data` can be specified.
Only one of `source_field`, `data`, or `use_default_value` can be specified.

@LucasG0 LucasG0 force-pushed the lgu-obj-conv-use-default-value branch from 17fee47 to 5498204 Compare September 24, 2025 16:49
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 (2)
infrahub_sdk/convert_object_type.py (2)

58-60: Harden validation: treat empty/whitespace source_field as “not set”

An empty or whitespace-only string shouldn’t count as “set”.

Apply this diff within the validator:

-        fields_set = [self.source_field is not None, self.data is not None, self.use_default_value is True]
+        fields_set = [bool(self.source_field and self.source_field.strip()), self.data is not None, self.use_default_value is True]

Optionally, enforce non-empty when provided:

# outside selected lines
from pydantic import BaseModel, model_validator, Field  # add Field

# and update the field definition:
source_field: str | None = Field(default=None, min_length=1)

54-54: Prefer Optional[bool] for use_default_value
Change

-    use_default_value: bool = False
+    use_default_value: bool | None = None

to align with other optional fields and prevent default False from appearing in serialized payloads.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 17fee47 and 5498204.

📒 Files selected for processing (1)
  • infrahub_sdk/convert_object_type.py (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.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/convert_object_type.py
⏰ 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). (6)
  • GitHub Check: unit-tests (3.13)
  • GitHub Check: unit-tests (3.11)
  • GitHub Check: integration-tests-latest-infrahub
  • GitHub Check: unit-tests (3.10)
  • GitHub Check: unit-tests (3.9)
  • GitHub Check: unit-tests (3.12)
🔇 Additional comments (2)
infrahub_sdk/convert_object_type.py (2)

39-39: Clearer error message formatting — LGTM

Backticks improve readability and consistency across validation errors.


48-50: Docstring now documents use_default_value and mutual exclusivity — nice

This addresses the earlier feedback to include the new option and the “only one of” rule.

@LucasG0 LucasG0 merged commit 6cdd780 into develop Sep 24, 2025
20 checks passed
@LucasG0 LucasG0 deleted the lgu-obj-conv-use-default-value branch September 24, 2025 22:56
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