Skip to content

Allow array variables in mail> operator parameters#1847

Closed
i10416 wants to merge 2 commits intomasterfrom
WM-2763
Closed

Allow array variables in mail> operator parameters#1847
i10416 wants to merge 2 commits intomasterfrom
WM-2763

Conversation

@i10416
Copy link
Copy Markdown

@i10416 i10416 commented Apr 16, 2026

Summary

  • Allow embedding array variables in to, cc, and bcc parameters of the mail> operator
  • Users can now use expressions like to: ${address_list} where address_list is an array

Problem

When users write YAML like this:

_export:
  address_list: ["aaa@example.com", "bbb@example.com"]
+send_message:
  mail>:
  to: ${address_list}

The template engine replaces ${address_list} with its JSON representation as a string: to: '["aaa@example.com", "bbb@example.com"]'

The old code using getList() expected an already-parsed array and failed on JSON strings.

Solution

Changed to use parseList() and parseListOrGetEmpty() which:

  1. Check if the value is a textual JSON string
  2. Parse the JSON string if needed
  3. Fall back to regular list parsing if not a string

This approach is already used by the for_each> operator for the same purpose.

Changes

  • Changed getList() to parseList() for the to parameter
  • Changed getListOrEmpty() to parseListOrGetEmpty() for cc and bcc parameters

Test Plan

  • Added sendToWithArrayVariable() test - verifies JSON string parsing for to parameter
  • Added sendCcWithArrayVariable() test - verifies JSON string parsing for cc parameter
  • Added sendBccWithArrayVariable() test - verifies JSON string parsing for bcc parameter
  • Tests simulate post-template-substitution state by setting values as JSON strings
  • This matches the testing pattern in ConfigTest.verifyParseList()

Verification

The fix is verified by:

  1. Existing Config.verifyParseList() test demonstrates parseList handles JSON strings
  2. Updated tests correctly simulate the variable substitution behavior
  3. Code analysis shows parseList calls tryParseNested which parses textual JSON

i10416 and others added 2 commits April 16, 2026 23:38
Changed mail> operator's to, cc, and bcc parameters to support
embedding array variables like ${address_list}.

Changes:
- Use parseList() instead of getList() for 'to' parameter
- Use parseListOrGetEmpty() instead of getListOrEmpty() for 'cc' and 'bcc'

The parseList methods evaluate variable expressions before falling back
to regular list parsing, enabling users to pass array variables.

Added test cases:
- sendToWithArrayVariable()
- sendCcWithArrayVariable()
- sendBccWithArrayVariable()

Fixes WM-2763
Related to WM-2579

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
The previous tests used ${address_list} as literal strings, which didn't
properly demonstrate how the parseList fix works. Updated tests now use
JSON string representations like ["a@ex.com", "b@ex.com"] which correctly
simulates what happens after Digdag's template engine processes variables.

This matches the pattern used in Config.verifyParseList() test and clearly
demonstrates that parseList can handle JSON strings while getList cannot.

Added detailed comments explaining the variable substitution process.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@i10416 i10416 closed this Apr 16, 2026
@i10416 i10416 deleted the WM-2763 branch April 16, 2026 15:06
@i10416 i10416 changed the title WM-2763: Allow array variables in mail> operator parameters Allow array variables in mail> operator parameters Apr 16, 2026
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.

1 participant