-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Switching incrementers causes jobs to have old job parameters #4073
Comments
If you change job parameters incrementing rules, you should change parameters validation rules as well. Those work together. You can't change the way parameters are incremented without updating the rules of how to validate them. Do you agree? So in your case, if you switch the incrementer, then you should switch the validator as well to ignore the, now invalid, obsolete parameters used by the previous incrementer (The |
I believe I did change the validator, Removing "run.id", and replacing it with another parameter name:
Unless by " switch the validator" you mean something else? To me the fact that the code grabs the next incrementor from the previous execution, assuming it's not changed, is the issue. Even if 99.999% the incrementor hasn't changed, it is possible. However I'm not familiar enough with the code to say if it's possible to catch this kind of issue, so it would be nice if at least the documentation mentioned this potential. |
Yes, I meant something else if necessary, that's why I said the I tried the scenario you described in this repo. Removing the old parameter from the required keys in the |
Thank you for looking into this.
I looked at the repo mentioned, it appears to replicate the scenario I described. However since the error "'run.id' being 'not explicitly optional or required'." did not appear. Looking closer, I was able to make the error occur if I added an optional key. If that is the only way to make it happen, it's my bad for not including it in the "Steps to reproduce". If so then: Either way I guess it could be argued that changing an incrementor falls under the "For more complex constraints, you can implement the interface yourself." line in the current documentation:
|
Thank you for your feedback. This is a bug in the implementation of In fact, with an optional key in place, removing As you mentioned, this could be unexpected and confusing, so it should be fixed (and not documented as you suggest). The fix will introduce a small breaking change, so I will plan it for a minor release rather than a patch release. |
Bug description
Switching the incrementer for a job causes new instances of that job to keep the old incrementer's parameters around, causing errors if you have a job parameters validator.
Actual error: "JobParametersInvalidException: The JobParameters contains keys that are not explicitly optional or required: [run.id]"
Environment
Spring boot 2.6.4
Spring batch 4.3.5
Java 1.8.0_312
H2 database saved to file
Steps to reproduce
If you start with the code from https://github.com/Apress/def-guide-spring-batch/blob/7db62ca34a1c582fce722f4f266681f29d29b12d/Chapter04/src/main/java/com/example/Chapter04/jobs/HelloWorldJob.java, you should be almost there
Expected behavior
For the new job to work, without caring that the old job use a different incrementor
I believe the
JobParametersBuilder.getNextJobParameters()
is at fault, specifically:nextParameters = incrementer.getNext(previousExecution.getJobParameters());
It appears to use the previous execution's job parameters, which would have the old, now invalid, parameter.
This is for sure an edge case, how often, would someone change the incrementer for a job? And I'm sure I can work around this issue if I changed my job name or deleted my h2 database. Hopefully there wasn't some warning about changing the incremeter that I missed.
The text was updated successfully, but these errors were encountered: