Mongoize is not called on update_all, when $set operator is used #5814
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.
During our upgrade of mongoid to 8.x version hit into issue that that custom type field classes stops working in update_all, when
$set operator is used:
This problem is not highlighted by the tests due to mongoize does not work, but BSON still able serialize strings and send it to database:
And in test case reloaded results from database - string value transformed to Integer by demongoize. Tests always stays green, however problem exists:
It is easy to find with couple of lines console output:
Output of rspec test will be
Issue happens due to misuse of the mongoize_for third param. It should be key (i.e. field key), not operator
In this case in mongoize_for field will be nil and it return original value without demongoization:
This issue exists at least at
8.1-stable
branch, but code is different there. I will provide separate PR to fix this issue in8.1-stable
branch.8.1-stable
fix is actually important for us (https://www.onepagecrm.com), we are aiming to make upgrade to 8.1.x, but do not go further for a minute.This PR also fix a problem describer by midnight-wonderer in discussion #5812
He also right about line with misuse of first attribute:
I've included this small suggested fix in this PR.