Skip to content

Check scoped step names when the flow reaches them - #5682

Open
thxwelchs wants to merge 2 commits into
spring-projects:mainfrom
thxwelchs:fix/job-scope-step-late-binding
Open

thxwelchs wants to merge 2 commits into
spring-projects:mainfrom
thxwelchs:fix/job-scope-step-late-binding

Conversation

@thxwelchs

@thxwelchs thxwelchs commented Nov 26, 2026 •

Copy link
Copy Markdown

Resolves #5680

Background

Since 6.0.6, FlowJob#doExecute checks for duplicate step names before the flow starts (#3757). The check calls getName() on every step of the flow.

Problem

  • For a @JobScope step, getName() goes through the scoped proxy and creates the target bean when the job starts.
  • Attributes bound with #{jobExecutionContext[...]} are resolved before earlier steps had a chance to store them, so they are injected as null and the step later runs with that value. The same job works with 6.0.5.

Fix

As agreed in #5680:

  • Steps that are not scoped are checked when the job starts, as before, including all branches and nested flows.
  • Scoped steps are checked when the flow reaches them, against the step names seen so far. The check never creates a scoped step itself, so scoped steps on branches that are not taken are not created.
  • An exception thrown by the check is logged at debug level and does not fail the job.

Tests cover late binding of jobExecutionContext, a scoped step on a branch that is not taken, duplicates between scoped steps and between a scoped and a non-scoped step, and a failing check.

@thxwelchs
thxwelchs force-pushed the fix/job-scope-step-late-binding branch from b305daa to 5c784e1 Compare November 26, 2026 03:24
Since the duplicate step name check was added to FlowJob, it calls
getName() on every step of the flow before the flow starts. For a job
scoped step, this goes through the scoped proxy and creates the target
bean right away, before earlier steps had a chance to store the values
bound with #{jobExecutionContext[...]}. Those values are injected as
null, and since the bean is cached in the job scope, the step later runs
with them.

The check now skips scoped steps, including in nested flows, so they are
only created when the flow reaches them. Scoped steps on branches that
are not taken are not created either. Looking up steps by name is not
affected.

Resolves spring-projects#5680

Signed-off-by: Taehun Lee <thxwelchs@gmail.com>
Skipping scoped steps in the duplicate step name check also stopped
reporting duplicates involving them. A scoped step is now checked when
the flow reaches it, against the step names seen so far, so the check
never creates a scoped step itself. An exception thrown by the check is
logged at debug level and does not fail the job.

Related to spring-projects#5680

Co-authored-by: Yanming Zhou <zhouyanming@gmail.com>
Signed-off-by: Taehun Lee <thxwelchs@gmail.com>
@thxwelchs thxwelchs changed the title Do not create scoped steps when checking for duplicate step names Check scoped step names when the flow reaches them Nov 27, 2026
@thxwelchs

Copy link
Copy Markdown
Author

Updated as discussed in #5680. @quaff I added you as a co-author, let me know if you'd rather not be.

@quaff

quaff commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

After reviewing changes in FlowJob, it make code more complex, the cost doesn't match the gain, see #5680 (comment), let wait for response from @fmbenhassine

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Job scoped steps are instantiated before the flow starts since 6.0.6, breaking late binding of jobExecutionContext

2 participants