Add description support for Python transforms#8678
Add description support for Python transforms#8678minitriga wants to merge 4 commits intorelease-1.9from
Conversation
WalkthroughThe PR adds an optional 🚥 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. 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
backend/tests/unit/git/test_transform_python_information.py (1)
92-92: Missing newline at end of file.The file should end with a trailing newline character for consistency with Python style conventions.
🔧 Add trailing newline
existing = _make_mock_transform(description="Same") local = _make_local_transform(description="Same") assert await InfrahubRepositoryIntegrator.compare_python_transform(existing, local) is True +🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@backend/tests/unit/git/test_transform_python_information.py` at line 92, The file ends without a trailing newline which violates Python style; open the test file containing the assertion using InfrahubRepositoryIntegrator.compare_python_transform (the test in test_transform_python_information.py), and add a single newline character at the end of the file (ensure the file ends with '\n') so the EOF is terminated by a newline.
🤖 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/unit/git/test_transform_python_information.py`:
- Line 92: The file ends without a trailing newline which violates Python style;
open the test file containing the assertion using
InfrahubRepositoryIntegrator.compare_python_transform (the test in
test_transform_python_information.py), and add a single newline character at the
end of the file (ensure the file ends with '\n') so the EOF is terminated by a
newline.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: cffe1596-170c-44ef-8347-3e1f59485f8a
📒 Files selected for processing (4)
backend/infrahub/git/integrator.pybackend/tests/fixtures/repos/car-dealership/initial__main/.infrahub.ymlbackend/tests/unit/git/__init__.pybackend/tests/unit/git/test_transform_python_information.py
| local = _make_local_transform(description="New description") | ||
| assert await InfrahubRepositoryIntegrator.compare_python_transform(existing, local) is False | ||
|
|
||
| @pytest.mark.anyio |
There was a problem hiding this comment.
you can remove these pytest marks
| def _make_mock_transform( | ||
| query_id: str = "query-id", | ||
| file_path: str = "transforms/test.py", | ||
| timeout: int = 10, | ||
| convert_query_response: bool = False, | ||
| description: str | None = None, | ||
| ) -> MagicMock: | ||
| mock = MagicMock() | ||
| mock.query.id = query_id | ||
| mock.file_path.value = file_path | ||
| mock.timeout.value = timeout | ||
| mock.convert_query_response.value = convert_query_response | ||
| mock.description.value = description | ||
| return mock |
There was a problem hiding this comment.
can this create a CorePythonTransform instead of a MagicMock so that it matches the method signature. keeping mocks to a minimum is usually best practice for testing, but Claude really likes to mock things
There was a problem hiding this comment.
Should be resolved now
There was a problem hiding this comment.
🧹 Nitpick comments (1)
backend/tests/unit/git/test_transform_python_information.py (1)
116-135: Consider adding create/update description-sync tests to match PR scope.Current tests validate model + compare paths well, but this PR also changes create/update threading of
description. A targeted unit test for those methods would reduce regression risk.I can draft the exact tests for
create_python_transform()andupdate_python_transform()payload assertions if you want.
Based on learnings: "Applies to backend/**/*.py : Write tests for new functionality in Python backend code".🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@backend/tests/unit/git/test_transform_python_information.py` around lines 116 - 135, Tests currently cover compare_python_transform but not create_python_transform or update_python_transform which now thread `description`; add unit tests that call InfrahubRepositoryIntegrator.create_python_transform(...) and InfrahubRepositoryIntegrator.update_python_transform(...) (or the class methods that wrap them) and assert the outgoing payloads/side-effects correctly include, omit, or preserve `description` for cases: description present in local (create includes it), description changed (update sends new description), description removed (update sends null/omission as your API expects), and description unchanged (no-op or unchanged payload). Locate tests near TestComparePythonTransform and mirror its async style, using _make_local_transform/_make_existing_transform helpers to build inputs and asserting the expected requests/returned objects.
🤖 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/unit/git/test_transform_python_information.py`:
- Around line 116-135: Tests currently cover compare_python_transform but not
create_python_transform or update_python_transform which now thread
`description`; add unit tests that call
InfrahubRepositoryIntegrator.create_python_transform(...) and
InfrahubRepositoryIntegrator.update_python_transform(...) (or the class methods
that wrap them) and assert the outgoing payloads/side-effects correctly include,
omit, or preserve `description` for cases: description present in local (create
includes it), description changed (update sends new description), description
removed (update sends null/omission as your API expects), and description
unchanged (no-op or unchanged payload). Locate tests near
TestComparePythonTransform and mirror its async style, using
_make_local_transform/_make_existing_transform helpers to build inputs and
asserting the expected requests/returned objects.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 62abf52c-655f-4286-b950-936059f11b5f
📒 Files selected for processing (1)
backend/tests/unit/git/test_transform_python_information.py
|
@minitriga your PR to the SDK should be integrated into the latest version of |
|
Sorry my bad, must have been another PR I thought that the SDK PR got merged earlier and was already in |
|
This PR has been inactive for 2 weeks and has been marked as stale. If you're still working on this, please:
The stale label will be removed automatically when there's new activity. |
fbe3d5d to
a31ff84
Compare
Thread the optional `description` field through the Python transform pipeline: get_python_transforms → create/compare/update methods. This achieves parity with Jinja2 transform description handling. The SDK-side change (InfrahubPythonTransformConfig.description) is in opsmill/infrahub-sdk-python#887. Closes #6382 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ub.yml - Introduced a new `description` field in the `InfrahubPythonTransformConfig` model to allow users to provide descriptions for Python transforms. - Updated the `TransformPythonInformation` model to include the `description` field. - Modified the backend integrator methods to handle the new `description` field during create, compare, and update operations. - Ensured backward compatibility by allowing existing Python transform definitions without a description to continue functioning without errors. - Added unit and integration tests to verify the correct handling of the `description` field in various scenarios, including parsing, syncing, and updating. - Updated relevant documentation and specifications to reflect the new feature.
…e kinds and relationship cardinalities
3d9f87f to
54c7829
Compare
Summary by CodeRabbit
New Features
Tests
Fixes #6382 — Python transforms in
.infrahub.ymldon't support adescriptionfield, even though Jinja2 transforms do and both types appear in the same table in the Infrahub UI. The database schema (CoreTransformation.description) already supports it for both types — the gap was in the config parsing and the repository integrator that syncs config to the database.descriptionthrough the Python transform pipeline:get_python_transforms()→create_python_transform()→compare_python_transform()→update_python_transform()descriptionfield toTransformPythonInformationdata modelDepends on: opsmill/infrahub-sdk-python#887
Changes
backend/infrahub/git/integrator.pydescriptiontoTransformPythonInformation,get_python_transforms,create_python_transform,compare_python_transform,update_python_transformbackend/tests/fixtures/repos/car-dealership/initial__main/.infrahub.ymldescriptionto a Python transform fixturebackend/tests/unit/git/test_transform_python_information.pyBefore / After
Before: Descriptions set on Python transforms in
.infrahub.ymlwere silently ignored during repository sync. The description column in the transforms table was always empty for Python transforms.After: Python transform descriptions are parsed from config, persisted on create, detected on change, and updated on sync — matching the existing Jinja2 transform behavior.
Test plan
TransformPythonInformationdefaultsdescriptiontoNoneTransformPythonInformationaccepts a description string valuecompare_python_transformreturnsTruewhen descriptions matchcompare_python_transformreturnsFalsewhen description is changed/added/removeddescriptioncontinue to work (backward compatible)🤖 Generated with Claude Code