Ensure uniqueness across all args if no keys are specified #1031
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.
Hello!
Today I spent a good chunk of time chasing down some weirdness with certain jobs not getting scheduled, and I'm pretty sure this is a bug 🐛 . In certain cases, the order of job insertion affects whether or not uniqueness is enforced. (I noticed this with
Oban.Pro.Engine.Smart
, and that seems to use the same function for determining uniqueness, so if this is an acceptable fix it would be great if it can be fixed there too!)Given a worker that has
unique: [fields: [:args]]
specified the following happens: inserting A first, and then B results in two separate jobs, as expected. But if you insert B first, and then insert A, it is considered to not be unique compared to B.Initially I just wanted to open an issue, but I got curious and figured I might as well try to fix it. There is no Postgres operator to determine if two jsonb fields are exactly equal, so the best way seems to be to use both the
@>
and<@
operators to ensure that they are completely the same. I'm not very familiar with SQLite, so I extrapolated the same principle into that engine, but there might be a better way.I added a test that initially confirmed the unexpected behaviour, and now confirms that it is consistent.
Lastly - locally
mix format --check-formatted
failed, but it is only upset by files that have not been changed in this PR, so I'm not sure what the best approach is there.