Fix id_partition interpolation with BSON::ObjectId #82
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.
Hey all 👋
I noticed recently that
id_partition
interpolation was not working any more in my project, it was alwaysnil
.As I investigated I noticed the reason is quite simple, the code expects the model instance
id
to be aString
, whereas it's aBSON::ObjectId
(and it has been so for a while in mongoid).I suspect it was probably a String in earlier version of mongoid? At some point it was working fine in my code because I have old folders with the
id_partition
but I can't tell exactly when it stopped working because I delete old files regularly.Anyway here is the fix I suggest (with an addition test for that): I added
BSON::ObjectId
to the supported types and.to_s
to convert it to aString
before thescan
. (.to_s
is a no-op if already a String). I tested this fix in my project and it restored the workingid_partition
interpolation.New test before my fix showing the problem:
Let me know if you have any questions!