IHS-114: Add diff data api endpoint
Why
The Python SDK's client.branch.diff_data() called GET /api/diff/data but that endpoint did not exist, returning a 404. Additionally, the SDK's URL builder was missing a ? separator before query parameters, producing malformed URLs like /api/diff/databranch=test-branch&branch_only=true.
Goal: make client.branch.diff_data() work end-to-end by implementing the missing REST endpoint and fixing the URL generation bug.
SDK PR https://github.com/opsmill/infrahub-sdk-python/pull/865
Closes https://github.com/opsmill/infrahub-sdk-python/issues/325
What changed
- New endpoint
GET /api/diff/data— returns the enriched data-level diff for a branch as a JSON array. UsesDiffRepository(the same backend used by the GraphQL diff tree query) andjsonable_encoderwith custom encoders forTimestampandTrackingIdto produce a fully serializable response. - Integration test — added
TestDiffAPI.test_diff_data_api_endpointintests/integration_docker/api/test_diff.pyto confirm the endpoint responds and returns a list.
No schema changes. No existing endpoint behavior changed. The /api/diff/files and /api/diff/artifacts endpoints are untouched.
How to review
backend/infrahub/api/diff/diff.py— the newget_diff_dataendpoint and itsjsonable_encoderusage withresponse_model=Nonebackend/tests/integration_docker/api/test_diff.py— the integration test
The response_model=None on the endpoint decorator is intentional: EnrichedDiffRoot is a dataclass with non-Pydantic types (Timestamp, TrackingId), so FastAPI's automatic Pydantic serialization is bypassed in favour of explicit jsonable_encoder pre-processing.
How to test
# Run the integration test
uv run pytest backend/tests/integration_docker/api/test_diff.py -v
Expected: test_diff_data_api_endpoint returns a list (empty [] for a branch with no changes).
Impact & rollout
- Backward compatibility: additive only — new endpoint, no existing behaviour changed
- Performance: no impact on existing endpoints
- Config/env changes: none
- Deployment notes: safe to deploy
Checklist
- Tests added/updated
- Changelog entry added (
uv run towncrier create ...) - External docs updated (if user-facing or ops-facing change)
- Internal .md docs updated (internal knowledge and AI code tools knowledge)
Summary by CodeRabbit
-
New Features
- Added a new API endpoint to retrieve enriched diff data with optional branch and time-range query parameters.
-
Tests
- Added integration test coverage for the diff data API endpoint.
-
Documentation
- OpenAPI/schema and generated client types updated to include the new endpoint.
- Changelog entry added documenting the new diff data API.