-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[NEEDS FEEDBACK] MONGOID-5382 RawValue for mongoize/demongoize #5368
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
base: master
Are you sure you want to change the base?
Conversation
|
I haven't thought about this PR yet but just from an initial look.... Wouldn't it be better to have Mongoid::RawValue have its own evolve method which just returns the inner value? Instead of hard coding checks everywhere? |
Yeah that thought crossed my mind too. Hmm... 🤔 |
|
@johnnyshields Can you please either rebase this PR on master or close it if no longer relevant. I also get the impression that this is a "solution in search of a problem", so to speak, namely that you are trying to get your idea of |
95501bb to
e9d314b
Compare
3d79b38 to
be716a0
Compare
|
@jamis can you please give me some feedback on the spec written above and the draft code in this PR? If I invest my time to complete this, will the MongoDB team merge it? |
This PR is a work-in-progress, code doesn't match spec below yet
MONGOID-5408 introduced a new class
Mongoid::RawValuewhich is used to represent uncastable values. MONGOID-5408 added support for the#evolve(cast-to-query) method, however, the concept can be extended to#mongoizeand#demongoize.The following is intended:
"use_raw_value_for_type_casting"(name TBD). The legacy behavior of this flag is "false" and the new behavior will be "true".mongoizeanddemongoizewill now return Mongoid::RawValue in case the object cannot be casted.raw_valueobject. This is done primarily fordemongoize, so that you can easily work with RawValues.InvalidValue(orInvalidAssignment, name TBD) error ifmongoizereturns aMongoid::RawValue. To get around this error You will still be able to assign a RawValue directly.To illustrate all this:
For reference, the current Mongoid 8.0 behavior is that both
#mongoizeand#demongoizecoerce uncastable values tonil, which is dangerous. Previously, in Mongoid 7.x and earlier, some cases of assignment resulted in errors being raised, however the logic was inconsistent and unintentional (e.g. errors happened to be raised because of bugs, which had the side effect of preventing some cases uncastable assignment.)