Skip to content

Add description support for Python transforms#8678

Open
minitriga wants to merge 4 commits intorelease-1.9from
gh-6382-python-transform-description
Open

Add description support for Python transforms#8678
minitriga wants to merge 4 commits intorelease-1.9from
gh-6382-python-transform-description

Conversation

@minitriga
Copy link
Copy Markdown
Contributor

@minitriga minitriga commented Mar 23, 2026

Summary by CodeRabbit

  • New Features

    • Python transforms now support an optional description for clearer documentation.
    • Descriptions are persisted and kept in sync during transform creation and updates.
    • Transform comparison now considers description differences to trigger updates when needed.
  • Tests

    • Added tests covering defaulting, persistence, synchronization, and comparison behavior for transform descriptions.

Fixes #6382 — Python transforms in .infrahub.yml don't support a description field, 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.

  • Thread description through the Python transform pipeline: get_python_transforms()create_python_transform()compare_python_transform()update_python_transform()
  • Add description field to TransformPythonInformation data model
  • Add test fixture with description on a Python transform entry
  • Add 6 unit tests covering the data model and compare method

Depends on: opsmill/infrahub-sdk-python#887

Changes

File Change
backend/infrahub/git/integrator.py Add description to TransformPythonInformation, get_python_transforms, create_python_transform, compare_python_transform, update_python_transform
backend/tests/fixtures/repos/car-dealership/initial__main/.infrahub.yml Add description to a Python transform fixture
backend/tests/unit/git/test_transform_python_information.py New: 6 tests for data model and compare method

Before / After

Before: Descriptions set on Python transforms in .infrahub.yml were 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

  • TransformPythonInformation defaults description to None
  • TransformPythonInformation accepts a description string value
  • compare_python_transform returns True when descriptions match
  • compare_python_transform returns False when description is changed/added/removed
  • Existing configs without description continue to work (backward compatible)

🤖 Generated with Claude Code

@minitriga minitriga requested a review from a team as a code owner March 23, 2026 17:17
@github-actions github-actions bot added the group/backend Issue related to the backend (API Server, Git Agent) label Mar 23, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 23, 2026

Walkthrough

The PR adds an optional description: str | None field to TransformPythonInformation and populates it from local Python transform configuration. create_python_transform and update_python_transform now persist and synchronize the description into the CoreTransformPython node payload. compare_python_transform includes description in its equality check so transforms are considered changed when descriptions differ. A test fixture YAML was updated to include a transform description, and unit tests were added to validate description behavior and comparison logic.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding description support for Python transforms, which matches the core objective of the PR.
Description check ✅ Passed The description covers Why (issue #6382 and the gap), What changed (threading description through the pipeline with file changes), Before/After behavior, and a comprehensive Test plan. All critical sections are populated with specific details.
Linked Issues check ✅ Passed The PR fully implements the requirement from issue #6382: Python transforms now support descriptions in .infrahub.yml, with parsing, persistence, change detection, and updates matching Jinja2 transform behavior.
Out of Scope Changes check ✅ Passed All changes are directly related to issue #6382: adding description support to Python transforms. The data model changes, fixture update, and unit tests are all within scope of threading description through the transform pipeline.

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

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 23, 2026

Merging this PR will not alter performance

✅ 12 untouched benchmarks


Comparing gh-6382-python-transform-description (a05cdd4) with release-1.9 (53f5567)

Open in CodSpeed

Copy link
Copy Markdown
Contributor

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

📥 Commits

Reviewing files that changed from the base of the PR and between 75b3fc7 and 329e626.

📒 Files selected for processing (4)
  • backend/infrahub/git/integrator.py
  • backend/tests/fixtures/repos/car-dealership/initial__main/.infrahub.yml
  • backend/tests/unit/git/__init__.py
  • backend/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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

you can remove these pytest marks

Comment on lines +37 to +50
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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Should be resolved now

Copy link
Copy Markdown
Contributor

@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)
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() and update_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

📥 Commits

Reviewing files that changed from the base of the PR and between 87b54b0 and ade114d.

📒 Files selected for processing (1)
  • backend/tests/unit/git/test_transform_python_information.py

@ogenstad
Copy link
Copy Markdown
Contributor

@minitriga your PR to the SDK should be integrated into the latest version of develop now can you rebase to check if that resolves the failing tests?

@ogenstad
Copy link
Copy Markdown
Contributor

Sorry my bad, must have been another PR I thought that the SDK PR got merged earlier and was already in infrahub-develop..

@github-actions
Copy link
Copy Markdown

This PR has been inactive for 2 weeks and has been marked as stale.

If you're still working on this, please:

  • Push new commits, or
  • Leave a comment to indicate this PR is still active

The stale label will be removed automatically when there's new activity.

@github-actions github-actions bot added the stale Marks stale issues and pull requests label Apr 15, 2026
@minitriga minitriga force-pushed the gh-6382-python-transform-description branch from fbe3d5d to a31ff84 Compare April 20, 2026 14:29
@minitriga minitriga closed this Apr 20, 2026
@minitriga minitriga reopened this Apr 20, 2026
minitriga and others added 3 commits April 21, 2026 11:27
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.
@minitriga minitriga changed the base branch from develop to release-1.9 April 21, 2026 10:27
@minitriga minitriga requested a review from a team as a code owner April 21, 2026 10:27
@minitriga minitriga force-pushed the gh-6382-python-transform-description branch from 3d9f87f to 54c7829 Compare April 21, 2026 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

group/backend Issue related to the backend (API Server, Git Agent) stale Marks stale issues and pull requests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants