Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JobRepositoryTestUtils#removeJobExecutions() Fails with Foreign Key Constraint Violation if Job Executions have Step Executions #4242

Closed
kzander91 opened this issue Nov 21, 2022 · 0 comments

Comments

@kzander91
Copy link

kzander91 commented Nov 21, 2022

Related to #4229.

Bug description
Running a Job and then using JobRepositoryTestUtils#removeJobExecutions() fails, because the method does not delete the StepExecutions.
The method selects the executions to delete with this code:

List<JobExecution> jobExecutions = this.jobRepository.findJobExecutions(jobInstance);
if (jobExecutions != null && !jobExecutions.isEmpty()) {
removeJobExecutions(jobExecutions);
}

But findJobExecutions(JobInstance) does not populate the execution's stepExecutions attribute (we are missing a call to stepExecutionDao#addStepExecutions(JobExecution)):
@Override
public List<JobExecution> findJobExecutions(JobInstance jobInstance) {
return this.jobExecutionDao.findJobExecutions(jobInstance);
}

The subsequent call to removeJobExecutions(jobExecutions) then won't delete the StepExecutions, due to getStepExecutions() being empty:

public void removeJobExecution(JobExecution jobExecution) {
for (StepExecution stepExecution : jobExecution.getStepExecutions()) {
this.jobRepository.deleteStepExecution(stepExecution);
}

This causes FK constraint violations when the job executions themselves are then deleted afterwards.

Environment
Spring Batch 5.0.0-SNAPSHOT (this commit)

Steps to reproduce

  1. Run a Job.
  2. Call JobRepositoryTestUtils#removeJobExecutions()

Expected behavior
Method call succeeds, all executions are deleted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants