Skip to content

Fix S2B generator: preview letters pushed to translation then removed on generate - #2146

Merged
ecino merged 1 commit into
18.0from
copilot/fix-s2b-correspondence-issue
Sep 3, 2026
Merged

Fix S2B generator: preview letters pushed to translation then removed on generate#2146
ecino merged 1 commit into
18.0from
copilot/fix-s2b-correspondence-issue

Conversation

Copilot AI commented Sep 2, 2026

Copy link
Copy Markdown

S2B letters written in a language the child cannot read were pushed to the translation platform then immediately removed when using the Preview → Generate workflow.

Two compounding bugs:

  • sbc_translation create() dispatched all new S2B letters (including Draft/preview) to the translation platform. Clicking "Preview" incorrectly queued the letter for translation.
  • generate_letters_job found existing Draft letters via self.letter_ids and called letter.write(vals) — resetting state to "Received in the system" and silently pulling the letter out of the translation queue without re-dispatching.

The discrepancy between local and staging: local test data typically doesn't require translation (original_lang in language_ids), so letters took the create_commkit() path and the bug was never exposed. Staging with real data hits the translation path every time.

Changes

  • sbc_translation/models/correspondence.py — skip Draft letters in create():

    # Draft letters (preview) are not ready to be dispatched yet
    if correspondence.state == "Draft":
        continue
  • sbc_compassion/models/correspondence_s2b_generator.py — delete existing Draft letters before non-preview generation so they go through create(), which correctly handles translation/CommKit dispatch:

    if letter and not preview_mode:
        draft_letters = letter.filtered(lambda l: l.state == "Draft")
        draft_letters.unlink()
        letter -= draft_letters

@ecino
ecino marked this pull request as ready for review September 3, 2026 05:26
@greptile-apps

greptile-apps Bot commented Sep 3, 2026

Copy link
Copy Markdown

Confidence Score: 5/5

No blocking failure remains.

The exercised manual-validation and preview-to-final flows route final S2B letters through local translation when the field office does not support the source language.

T-Rex T-Rex Logs

What T-Rex did

    • Ran a narrow Python harness to exercise the changed production method bodies of the parent revision and the current revision.
    • In the current revision, validation dispatches to a local translate path for an unsupported language, and after a preview the Draft was removed and replaced with a newly created final correspondence.
    • The fixes pinpointed in sbc_translation and related generator remove Draft creation from the flow and ensure validate() dispatch occurs after the parent validation.
    • The harness shows that final generation uses the normal create() path, preserving the dispatch route by removing the Draft preview.
    • The validation artifacts include the after-state executable and harness sources, confirming reproducibility of the test run.

View all artifacts

T-Rex Ran code and verified through T-Rex

Reviews (3): Last reviewed commit: "T3404 Fix S2B generator: prevent preview..." | Re-trigger Greptile

Comment thread sbc_translation/models/correspondence.py Outdated
@ecino
ecino force-pushed the copilot/fix-s2b-correspondence-issue branch from b2b43e0 to e33d00a Compare September 3, 2026 05:53
… translation and removed on generate

- Skip Draft letters in create() so that preview does not trigger translation dispatch or commkit creation.
- Delete any Draft (preview) letters for a sponsorship before generating for real, forcing them through the create() path which correctly handles translation/commkit dispatch.
@ecino
ecino force-pushed the copilot/fix-s2b-correspondence-issue branch from e33d00a to 9636a26 Compare September 3, 2026 06:41
@ecino
ecino merged commit fa49123 into 18.0 Sep 3, 2026
2 checks passed
@ecino
ecino deleted the copilot/fix-s2b-correspondence-issue branch September 3, 2026 06:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants