allow removing properties from attributes in merge logic#8601
allow removing properties from attributes in merge logic#8601
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughModified serializer logic to refine when attribute property removals are skipped: value-type property removals are suppressed unless the whole attribute is being removed, while other property removals may proceed. Added parameterized tests that exercise single-property updates and HAS_SOURCE property changes across branch diffs and merges (including cases where the source is cleared), duplicated in the diff. Added a changelog entry documenting the fix to attribute source handling during merges. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 📝 Coding Plan
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. Comment Tip CodeRabbit can use Trivy to scan for security misconfigurations and secrets in Infrastructure as Code files.Add a .trivyignore file to your project to customize which findings Trivy reports. |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
backend/tests/component/core/diff/test_diff_and_merge.py (1)
670-681: Add a Google-style docstring to the new test method.Line 670 introduces a new test function without the required docstring format.
Proposed update
async def test_single_property_update( self, db: InfrahubDatabase, diff_repository: DiffRepository, @@ new_property: bool, expected_action: DiffAction, ) -> None: + """Validate merge behavior for single-property source updates/removals. + + Args: + db: Database handle. + diff_repository: Diff repository fixture. + default_branch: Default branch fixture. + person_john_main: Source person fixture. + person_jane_main: Target person fixture. + person_alfred_main: Alternate source fixture. + car_camry_main: Car fixture with owner relationship. + new_property: Whether source should be set (True) or cleared (False). + expected_action: Expected diff action for the property scenario. + + Returns: + None. + """As per coding guidelines,
**/*.py: “Always use triple quotes (""") for Python docstrings” and “Follow Google-style docstring format in Python”, including Args/Returns sections.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@backend/tests/component/core/diff/test_diff_and_merge.py` around lines 670 - 681, The new test function test_single_property_update is missing a Google-style triple-quoted docstring; add a top-level """...""" docstring above the async def that briefly describes the test purpose, then include Google-style Args: listing parameters like db, diff_repository, default_branch, person_john_main, person_jane_main, person_alfred_main, car_camry_main, new_property, expected_action with their types/meanings, and a Returns: section (e.g., None) — ensure the docstring follows the project's Google-style format and uses triple double-quotes.backend/tests/component/core/diff/test_diff_calculator.py (1)
4543-4543: Prefer a full Google-style docstring for the new test.Line 4543 uses a one-liner docstring; consider adding structured sections (
Args,Returns, and if applicableRaises/Examples) to match repository standards.As per coding guidelines, "**/*.py: Follow Google-style docstring format in Python; Include Args/Parameters section in Python docstrings without typing information; Include Returns section in Python docstrings; Include Raises section in Python docstrings; Include Examples section in Python docstrings."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@backend/tests/component/core/diff/test_diff_calculator.py` at line 4543, Replace the one-line docstring ("Test that updating or removing a HAS_SOURCE property from an attribute on a branch is captured in the diff.") with a full Google-style docstring: add a short summary line, an Args section (describe any parameters if the test takes fixtures or inputs; otherwise note none), a Returns section (state None), and a Raises section if the test asserts exceptions (or omit/explicitly state none), and optionally an Examples section; ensure the docstring follows repository Google-style format and is placed directly above the test function that contains the current one-liner.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@backend/tests/component/core/diff/test_diff_and_merge.py`:
- Around line 670-681: The new test function test_single_property_update is
missing a Google-style triple-quoted docstring; add a top-level """..."""
docstring above the async def that briefly describes the test purpose, then
include Google-style Args: listing parameters like db, diff_repository,
default_branch, person_john_main, person_jane_main, person_alfred_main,
car_camry_main, new_property, expected_action with their types/meanings, and a
Returns: section (e.g., None) — ensure the docstring follows the project's
Google-style format and uses triple double-quotes.
In `@backend/tests/component/core/diff/test_diff_calculator.py`:
- Line 4543: Replace the one-line docstring ("Test that updating or removing a
HAS_SOURCE property from an attribute on a branch is captured in the diff.")
with a full Google-style docstring: add a short summary line, an Args section
(describe any parameters if the test takes fixtures or inputs; otherwise note
none), a Returns section (state None), and a Raises section if the test asserts
exceptions (or omit/explicitly state none), and optionally an Examples section;
ensure the docstring follows repository Google-style format and is placed
directly above the test function that contains the current one-liner.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 243bcc9b-022c-422a-9d7c-b9809cb1046f
📒 Files selected for processing (3)
backend/infrahub/core/diff/merger/serializer.pybackend/tests/component/core/diff/test_diff_and_merge.pybackend/tests/component/core/diff/test_diff_calculator.py
ogenstad
left a comment
There was a problem hiding this comment.
Would be good with a news fragment for the resolved bug as well.
fixes #8583
the logic that serializes a diff and passes it to a cypher query during a merge was excluding removed properties of attributes if the attribute was not completely removed. for example, if the source of an attribute is deleted on a branch (like if the attribute stops using a profile), then this change would not make it back to the default branch during a merge
fix is a small change to make sure we send the property removals on to the merge query
adds two component tests covering this situation
Summary by CodeRabbit
Bug Fixes
Tests