Skip to content

fix(workflows): list-literal expression ignores trailing/empty commas#3631

Merged
mnriem merged 1 commit into
github:mainfrom
jawwad-ali:fix/expression-list-literal-empty-comma
Jul 22, 2026
Merged

fix(workflows): list-literal expression ignores trailing/empty commas#3631
mnriem merged 1 commit into
github:mainfrom
jawwad-ali:fix/expression-list-literal-empty-comma

Conversation

@jawwad-ali

Copy link
Copy Markdown
Contributor

What

A workflow list-literal expression with a trailing comma evaluates to a list with a spurious None:

{{ [1, 2,] }}   ->  [1, 2, None]      (expected [1, 2])

_split_top_level_commas("1, 2,") returns ['1', ' 2', '']; the empty segment flows through _evaluate_simple_expression(''), which resolves as an empty dot-path to None. Leading/double commas hit the same path. This silently widens membership tests ({{ x in [a, b,] }}) and renders a stray None in joins. Python and Jinja2 both tolerate trailing commas.

Fix

Drop whitespace-empty segments from the comprehension (if i.strip()). An intentional empty-string element is preserved, because its segment strips to "''" (truthy) — ['', 'a'] still yields ['', 'a']. This completes the quoted-comma handling added in #3134.

Test

test_list_literal_ignores_trailing_and_empty_commas: [1, 2,] and [1,, 2][1, 2]; ['', 'a']['', 'a'] — fails before (trailing None), passes after.


🤖 Written with the assistance of Claude Code (AI). Bug self-found; fix/tests verified locally (fail-before / pass-after), ruff clean.

A workflow list-literal expression with a trailing (or leading/double) comma —
'{{ [1, 2,] }}' — evaluated to [1, 2, None]: _split_top_level_commas returns a
trailing empty segment, which _evaluate_simple_expression resolves as an empty
dot-path to None. That silently widens membership tests and renders a stray
None in joins. Python and Jinja2 both tolerate trailing commas.

Drop whitespace-empty segments from the comprehension. An intentional
empty-string element ('') survives because its segment strips to "''" (truthy),
so ['', 'a'] is preserved. Completes the quoted-comma handling from github#3134.

Test: [1, 2,] and [1,, 2] -> [1, 2]; ['', 'a'] -> ['', 'a'] (fails before:
trailing None).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI 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.

Pull request overview

Fixes list-literal parsing so empty comma segments no longer produce spurious None elements.

Changes:

  • Filters whitespace-empty list segments.
  • Preserves explicit empty-string elements.
  • Adds regression coverage for trailing and repeated commas.
Show a summary per file
File Description
src/specify_cli/workflows/expressions.py Ignores empty list-literal segments.
tests/test_workflows.py Adds list parsing regression tests.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Medium

@mnriem
mnriem merged commit cef00a1 into github:main Jul 22, 2026
12 checks passed
@mnriem

mnriem commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Thank you!

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.

3 participants