Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem:
#enqueue
method mutates the options hash which includes priority, queue name, etc. This causes problems, if the same hash is used to create another job. In general, mutating method arguments is unexpected and a bad practise (might be a matter of taste but at least in my opinion it is a bit bad).Because of this, creating a second job with the same options fails and throws an error
ActiveRecord::StatementInvalid: SQLite3::ConstraintException: NOT NULL constraint failed
In my application when I first discovered this issue, my DB schema was a bit outdated and it allowed NULL values for priority. The job was successfully written to the database, but it contained the parameters that belonged to the first job (that is,
id: 1
instead ofid: 2
, see the steps to reproduce).Solution: Clone the hash before mutating it
Steps to reproduce: