Skip to content

Conversation

@minitriga
Copy link
Contributor

@minitriga minitriga commented Sep 15, 2025

Summary by CodeRabbit

  • New Features

    • You can clear optional dropdown attributes by setting them to None; the generated payload now explicitly includes null for that field.
  • Bug Fixes

    • Input data generation no longer omits optional dropdown fields set to None after user mutation.
  • Tests

    • Added tests validating dropdown attributes, including clearing values to None and checking the resulting payload.
  • Chores

    • Updated changelog to document clearing optional dropdown attributes.

@coderabbitai
Copy link

coderabbitai bot commented Sep 15, 2025

Walkthrough

Attribute input generation now preserves explicit None for optional attributes that have been mutated: when value is None and schema.optional and value_has_been_mutated, _generate_input_data sets data["value"] = None. Tests add an async pytest fixture location_schema_with_dropdown that adds a Dropdown status attribute to the Location schema and a new test verifying that setting node.status = None produces generated payload data containing status with value: None alongside other fields. A changelog entry (changelog/549.fixed.md) documents the change.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
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.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The provided title "Add support for clearing optional attributes" is concise and accurately reflects the primary change in the diff: allowing optional attributes to be cleared by handling None in infrahub_sdk/node/attribute.py, with accompanying tests and changelog entries. It is specific enough for a reviewer to understand the main intent without extraneous detail. The title therefore aligns well with the changeset.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch atg-20250915-ifc-1853

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6ebcc87 and 4993c13.

📒 Files selected for processing (3)
  • changelog/535.fixed.md (1 hunks)
  • changelog/549.fixed.md (1 hunks)
  • infrahub_sdk/node/attribute.py (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • changelog/535.fixed.md
  • changelog/549.fixed.md
🧰 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/node/attribute.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.12)
  • GitHub Check: unit-tests (3.13)
  • GitHub Check: integration-tests-latest-infrahub
🔇 Additional comments (1)
infrahub_sdk/node/attribute.py (1)

79-81: Correct: allow clearing mutated optional attributes with value=None

This meets the PR objective and is generic (applies to all optional kinds, not just Dropdown). Please add at least one non-Dropdown test (e.g., optional string) to prevent regressions.


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 15, 2025

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: 4993c13
Status: ✅  Deploy successful!
Preview URL: https://111a9994.infrahub-sdk-python.pages.dev
Branch Preview URL: https://atg-20250915-ifc-1853.infrahub-sdk-python.pages.dev

View logs

@codecov
Copy link

codecov bot commented Sep 15, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@            Coverage Diff             @@
##           stable     #548      +/-   ##
==========================================
+ Coverage   75.59%   75.65%   +0.06%     
==========================================
  Files         100      100              
  Lines        8892     8894       +2     
  Branches     1750     1751       +1     
==========================================
+ Hits         6722     6729       +7     
+ Misses       1688     1685       -3     
+ Partials      482      480       -2     
Flag Coverage Δ
integration-tests 34.68% <0.00%> (+<0.01%) ⬆️
python-3.10 48.17% <100.00%> (+0.04%) ⬆️
python-3.11 48.20% <100.00%> (+0.06%) ⬆️
python-3.12 48.15% <100.00%> (+0.06%) ⬆️
python-3.13 48.17% <100.00%> (+0.09%) ⬆️
python-3.9 46.80% <100.00%> (+0.04%) ⬆️
python-filler-3.12 24.99% <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/node/attribute.py 95.00% <100.00%> (+0.12%) ⬆️

... and 1 file with indirect coverage changes

🚀 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: 0

🧹 Nitpick comments (4)
changelog/7218.fixed.md (1)

1-1: Changelog entry reads well; tiny wording/style nit

Consider tightening and matching the schema kind casing.

-Allow the ability to clear optional dropdown attributes by setting them to None.
+Allow clearing optional Dropdown attributes by setting them to None.
infrahub_sdk/node/attribute.py (1)

78-81: Include properties on clear; avoid early return so flags propagate

When clearing a Dropdown to None, we likely still want to carry attribute properties (e.g., is_protected). Let the function continue so the flags/objects sections run, and keep the return shape consistent.

-        if self.value is None:
-            if self._schema.kind == "Dropdown" and self._schema.optional:
-                data["value"] = None
-            return data
+        if self.value is None:
+            if self._schema.kind == "Dropdown" and self._schema.optional:
+                # Explicit clear for optional Dropdowns; continue so properties are included.
+                data["value"] = None
+            else:
+                return data
tests/unit/sdk/conftest.py (1)

180-220: Optional: reduce duplication with base schema

You could build from location_schema data and append the status attribute to minimize drift between fixtures.

tests/unit/sdk/test_node.py (1)

1373-1399: Optional: assert behavior with exclude_unmodified=True

Clearing should count as a modification; asserting this guards regressions in strip-unmodified logic.

     assert node._generate_input_data()["data"] == {
         "data": {
             "name": {"value": "JFK1"},
             "description": {"value": "JFK Airport"},
             "type": {"value": "SITE"},
             "status": {"value": None},
             "primary_tag": None,
         }
     }
+
+    # Clearing should still be emitted when excluding unmodified fields
+    input_data = node._generate_input_data(exclude_unmodified=True)
+    assert input_data["data"]["data"]["status"] == {"value": None}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 10618ee and 1117f1a.

📒 Files selected for processing (4)
  • changelog/7218.fixed.md (1 hunks)
  • infrahub_sdk/node/attribute.py (1 hunks)
  • tests/unit/sdk/conftest.py (1 hunks)
  • tests/unit/sdk/test_node.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.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/node/attribute.py
  • tests/unit/sdk/test_node.py
  • tests/unit/sdk/conftest.py
tests/unit/**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

Place and write unit tests under tests/unit/ (isolated component tests)

Files:

  • tests/unit/sdk/test_node.py
  • tests/unit/sdk/conftest.py
tests/**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

Use the custom pytest plugin (infrahub_sdk.pytest_plugin) fixtures for clients, configuration, and Infrahub-specific testing

Files:

  • tests/unit/sdk/test_node.py
  • tests/unit/sdk/conftest.py
🧬 Code graph analysis (2)
tests/unit/sdk/test_node.py (5)
tests/unit/sdk/conftest.py (2)
  • client (32-33)
  • location_schema_with_dropdown (181-219)
infrahub_sdk/node/node.py (1)
  • _generate_input_data (195-281)
infrahub_sdk/node/attribute.py (3)
  • value (66-67)
  • value (70-72)
  • _generate_input_data (74-105)
infrahub_sdk/node/relationship.py (1)
  • _generate_input_data (60-61)
infrahub_sdk/node/related_node.py (1)
  • _generate_input_data (128-145)
tests/unit/sdk/conftest.py (2)
infrahub_sdk/schema/main.py (4)
  • NodeSchemaAPI (311-313)
  • NodeSchema (306-308)
  • convert_api (283-284)
  • convert_api (307-308)
infrahub_sdk/yaml.py (1)
  • data (147-150)
⏰ 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). (4)
  • GitHub Check: unit-tests (3.12)
  • GitHub Check: unit-tests (3.13)
  • GitHub Check: integration-tests-latest-infrahub
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (3)
infrahub_sdk/node/attribute.py (1)

78-81: Correctly surfaces null for optional Dropdowns

This fixes the inability to clear optional Dropdown attributes by emitting {"value": None}. Works with existing _generate_input_data plumbing in node.py.

tests/unit/sdk/conftest.py (1)

180-220: Good, focused fixture for Dropdown coverage

The fixture mirrors location_schema and adds a Dropdown cleanly; fits existing test patterns.

tests/unit/sdk/test_node.py (1)

1373-1399: Solid test validating clear-to-null behavior across async/sync nodes

Covers initial value, clear to None, and expected payload shape including primary_tag: None.

@minitriga minitriga changed the title Add support for clearing optional dropdown attributes Add support for clearing optional attributes Sep 19, 2025
@minitriga minitriga merged commit f321523 into stable Sep 22, 2025
20 checks passed
@minitriga minitriga deleted the atg-20250915-ifc-1853 branch September 22, 2025 08:47
minitriga added a commit that referenced this pull request Sep 22, 2025
* add support for clearing optional dropdown attributes and enhance tests for dropdown handling

* add changelog entry for clearing optional dropdown attributes

* refactor: update branch handling in changelog and allow clearing optional attributes if mutated

Co-authored-by: Alex Gittings <[email protected]>
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.

3 participants