[bug] evolve is weird #5671
Replies: 3 comments 1 reply
-
To make it more approachable as test cases, I expect BuggyModel.create!({ _id: '01' })
BuggyModel.where({ _id: '01' }).first_or_create!
BuggyModel.where({ _id: '02' }).first_or_create! to create exactly two documents without raising an exception. (on an originally-blank collection) BuggyModel.find('01')
BuggyModel.where({ _id: '01' }).first
BuggyModel.where({ _id: '02' }).first to fetch I can't seem to accomplish that with any configurations I can come up with. P.S. If you are curious, what are the real-world use cases: I use certificate thumbprints as |
Beta Was this translation helpful? Give feedback.
-
Hey @midnight-wonderer -- this does sound like a bug! I've added an issue for it on our tracker (here: https://jira.mongodb.org/browse/MONGOID-5633) and we'll discuss it as a team on Monday. I can't make any promises that we'll get to it right away, but you can follow that issue if you'd like. |
Beta Was this translation helpful? Give feedback.
-
OK seems to work on my end too. class HexBytes
class << self
def mongoize(hex_string)
# idempotent handling
return hex_string if hex_string.is_a?(::BSON::Binary)
return nil unless hex_string.present?
[hex_string].pack('H*').then do |bin_content|
::BSON::Binary.new(bin_content)
end
end
def demongoize(binary)
# idempotent handling
return binary if binary.is_a?(::String)
return nil unless binary.present?
binary.data.then do |bin_content|
return nil unless bin_content.present?
bin_content.unpack1('H*')
end
end
def evolve(hex_string)
mongoize(hex_string)
end
end
end Thanks for the investigation and the recommendation regarding From my memory, I don't recall the document mentioning anything regarding idempotency, but some example includes something I don't understand, so I did not implement similar functionalities to make the oddity noticeable when something went wrong. Thanks a lot; you may close this and probably update the document, then. P.S. In the application I am working on, the string is supposed to be a hex string; if not, someone is probably doing the integration wrong. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a simple model with custom field types here:
With the declaration, this works:
but these failed:
So I remove
evolve
:Now the test cases above work, but:
Beta Was this translation helpful? Give feedback.
All reactions