Skip to content

fix(api): drop scheduled adjustments from v2 transfer initiation instead of blanking them - #822

Open
breken-ai wants to merge 1 commit into
formancehq:mainfrom
breken-ai:fix/v2-scheduled-adjustment-blank-entry
Open

breken-ai wants to merge 1 commit into
formancehq:mainfrom
breken-ai:fix/v2-scheduled-adjustment-blank-entry

Conversation

@breken-ai

Copy link
Copy Markdown

Problem

GET /v2/transfer-initiations/{id} returns a blank entry in relatedAdjustments for every scheduled transfer or payout.

translateAdjustments sizes its result with make(..., len(from)) and assigns to[i]. When translateStatus drops a SCHEDULED_FOR_PROCESSING adjustment, the continue leaves index i at its zero value, so the entry is still serialised:

{"adjustmentID":"","createdAt":"0001-01-01T00:00:00Z","status":"","error":"","metadata":null}

createPayout and createTransfer write a SCHEDULED_FOR_PROCESSING adjustment whenever scheduledAt is in the future, so every scheduled initiation hits this path. The generated v2 SDK then cannot decode the response, because "" is not a TransferInitiationStatus:

invalid value for TransferInitiationStatus:

The behaviour dates from #374 (2025-03-24), which introduced the drop. #821 routed the get handler through translateLastStatus but kept this loop as it was.

Fix

Build the slice with append (capacity len(from)), so an adjustment that translateStatus drops is actually left out. NOT_INITIATED is still reported as FAILED, as before.

Tests

  • New spec in handler_transfer_initiations_get_test.go. It returns [PROCESSING, SCHEDULED_FOR_PROCESSING] adjustments from the mocked backend, then checks:
    • exactly one PROCESSING entry comes back;
    • the body decodes into the SDK's components.TransferInitiationResponse.
  • On main (e5c4afad) the spec fails with len: 2 (the second entry is the blank one). With the fix it passes.
  • go test ./internal/api/v2/ ./internal/api/v3/ passes, also with GOTOOLCHAIN=go1.26.1.
  • go build ./... and go vet ./internal/api/v2/ pass.
  • golangci-lint run --build-tags it ./internal/api/v2/ (v2.14, repo .golangci.yml) reports 0 issues.

This PR was prepared by an AI agent (Claude Code, run by breken-ai). The regression test and checks above were run locally before opening it.

🤖 Generated with Claude Code

…ead of blanking them

translateAdjustments pre-sized its result with len(from) and then skipped
SCHEDULED_FOR_PROCESSING adjustments with continue, which left a
zero-valued entry in their slot. GET /v2/transfer-initiations/{id} on any
scheduled transfer returned an adjustment with an empty adjustmentID, a
0001-01-01 createdAt and an empty status, which the generated v2 SDK
rejects (invalid value for TransferInitiationStatus).

Build the slice with append so dropped adjustments are really dropped.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@breken-ai
breken-ai requested a review from a team as a code owner September 26, 2026 00:00

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@NumaryBot NumaryBot added risk: medium NumaryBot classified this pull request as medium risk. bot-reviewed NumaryBot completed its review workflow for the current head. review-inconclusive NumaryBot could not prove that the review gate is satisfied. review-approved The NumaryBot review gate is satisfied for the current head. and removed risk: medium NumaryBot classified this pull request as medium risk. bot-reviewed NumaryBot completed its review workflow for the current head. review-inconclusive NumaryBot could not prove that the review gate is satisfied. labels Sep 26, 2026

@NumaryBot NumaryBot left a comment

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.

The required automated review completed with no remaining findings.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot-reviewed NumaryBot completed its review workflow for the current head. review-approved The NumaryBot review gate is satisfied for the current head. risk: medium NumaryBot classified this pull request as medium risk.

Development

Successfully merging this pull request may close these issues.

2 participants