Open patryk-matis opened 1 year ago
Hi,I don’t use Mongodb. Most likely these are C objects that don’t provide a standard Python object interface that DeepDiff can use to compare them. That’s why when you convert them to strings, they work.On Mar 20, 2023, at 2:34 AM, Patryk Matis @.***> wrote: Describe the bug DeepDiff is not pointing out different objectIds (bson/mongodb) in dicts. To Reproduce Create two dicts with two different ObjectId inside of them and use DeepDiff() Expected behavior {'old_value': ObjectId('64131f792bbc01b7f84f1dd7'), 'new_value': ObjectId('64131f792bbc01b7f84f1db1'} OS, DeepDiff version and Python version (please complete the following information):
OS: Win11/WSL Python Version 3.9.16 DeepDiff Version 6.3.0
Additional context Parsing these objectIds to a string using str() works well, but this is just a workaround
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: @.***>
I wonder if we need to provide some sort of API for people to be able to register objects like above to DeepHash and let it know how it should be computing their hash. Something like custom_hash_for_types={bson: lambda x: x.some_attribute}
What do you think?
Hi @patryk-matis Please provide reproducible code. Otherwise, I plan to close the tickets that I can't reproduce.
I have the same problem:
My code:
deepdiff.DeepDiff({"a": bson.ObjectId("64235a0920937280bdd9bab9")}, {"a": bson.ObjectId("64235a0920937280bdd9bab4")})
gives the result {}
I tried setting up a custom operator for this and couldn't get it to work...
class ObjectIdOperator(BaseOperator):
def match(level):
return (
level.t1
and level.t2
and isinstance(level.t1, ObjectId)
and isinstance(level.t2, ObjectId)
)
def give_up_diffing(level, diff_instance):
return level.t1 == level.t2
Describe the bug DeepDiff is not pointing out different objectIds (bson/mongodb) in dicts.
To Reproduce Create two dicts with two different ObjectId inside of them and use DeepDiff()
Expected behavior {'old_value': ObjectId('64131f792bbc01b7f84f1dd7'), 'new_value': ObjectId('64131f792bbc01b7f84f1db1'}
OS, DeepDiff version and Python version (please complete the following information):
Additional context Parsing these objectIds to a string using str() works well, but this is just a workaround