Skip to content

ExecutionContext dirty flag is never cleared #5249

Closed

Description

@marschall

Bug description
The dirty flag of ExecutionContext is never cleared because org.springframework.batch.infrastructure.item.ExecutionContext#clearDirtyFlag() is never called.

Environment
Spring Batch version 6.0.2
Java version: 17.0.1
Database: H2 2.4.240

Steps to reproduce

  • Dirty a job or step execution context by calling one of the put* methods
  • Call JobRepository#updateExecutionContext
  • Call ExecutionContext#isDirty()

Expected behavior
I would expect org.springframework.batch.core.repository.JobRepository#updateExecutionContext(StepExecution) and org.springframework.batch.core.repository.JobRepository#updateExecutionContext(JobExecution) to clear the dirty flag.

Minimal Complete Reproducible example
Add to org.springframework.batch.core.repository.support.AbstractJobRepositoryIntegrationTests

	/*
	 * Save execution context clears the dirty flag.
	 */
	@Test
	void testUpdateRestesDirtyFlag() {
		JobInstance jobInstance = jobRepository.createJobInstance(job.getName(), jobParameters);
		JobExecution jobExec = jobRepository.createJobExecution(jobInstance, jobParameters, new ExecutionContext());
		jobExec.setStartTime(LocalDateTime.now());
		ExecutionContext ctx = new ExecutionContext();
		ctx.put("crashedPosition", 7);
		jobExec.setExecutionContext(ctx);
		assertTrue(ctx.isDirty());
		jobRepository.updateExecutionContext(jobExec);
		assertFalse(ctx.isDirty());
		
		Step step = new StepSupport("step1");
		StepExecution stepExec = jobRepository.createStepExecution(step.getName(), jobExec);
		ctx = new ExecutionContext(ctx);
		ctx.put("crashedPosition", 8);
		stepExec.setExecutionContext(ctx);
		assertTrue(ctx.isDirty());
		jobRepository.updateExecutionContext(stepExec);
		assertFalse(ctx.isDirty());
	}

Activity

  1. added
    status: waiting-for-triage
    on Feb 1, 2026
  2. quaff commented on Feb 2, 2026

    @quaff
    Contributor

    Indeed, context.clearDirtyFlag() in called only in ExecutionContextTests, you should submit an PR instead.

  3. added a commit that references this issue on Feb 2, 2026
    a071f53
  4. marschall commented on Feb 2, 2026

    @marschall
    ContributorAuthor

    I see there is already a PR. Is that indeed the indented behaviour that the repositories clear the context dirty flag after updating?

  5. added a commit that references this issue on Feb 2, 2026
    347efed
  6. fmbenhassine commented on May 29, 2026

    @fmbenhassine
    Contributor

    Is that indeed the indented behaviour that the repositories clear the context dirty flag after updating?

    Yes, every time the execution context is synchronized with the database, it should be considered fresh again (ie no updates happened since the last commit) and therefore I also expect the "dirty" flag to be cleared on updates.

  7. added
    for: backport-to-5.2.x
    and removed
    status: waiting-for-triage
    on May 29, 2026
  8. added this to the 6.0.4 milestone on May 29, 2026
  9. added a commit that references this issue on May 29, 2026
    b3f4af8
  10. added a commit that references this issue on May 29, 2026
    a27515e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: backport-to-5.2.xin: coretype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions