seperman / deepdiff

DeepDiff: Deep Difference and search of any Python object/data. DeepHash: Hash of any object based on its contents. Delta: Use deltas to reconstruct objects by adding deltas together.
http://zepworks.com
Other
2.03k stars 223 forks source link

Wrong calculation with ignore_order = True #189

Closed JeffXue closed 4 years ago

JeffXue commented 4 years ago

To Reproduce

from deepdiff import DeepDiff

record = [{'in': 'body', 'name': 'params', 'description': 'params', 'required': True, 'schema': {'type': 'array', 'items': {'__ref': '#/definitions/CreateCartItemParam'}}}]

body = [{'in': 'body', 'name': 'params', 'description': 'params', 'required': True, 'schema': {'type': 'array', 'items': {'__ref': {'type': 'object', 'required': ['count'], 'properties': {'checked': {'type': 'boolean', 'description': '是否将购物车更新标记为选中状态,默认新加入到购物车的商品为选中状态,如果不填则不更新这个状态'}, 'count': {'type': 'number', 'description': '商品数量,这个数量指更新之后最终的数量,如果更新成0表示会删除这个记录,必填'}, 'multiUnitId': {'type': 'integer', 'format': 'int64', 'description': '商品多单位Id,一个购物车里面的记录是skuId+multiUnitId唯一的,如果不传id,此值必填'}, 'skuId': {'type': 'integer', 'format': 'int64', 'description': '商品skuId,一个购物车里面的记录是skuId+multiUnitId唯一的,如果不传id,此值必填'}, 'temporary': {'type': 'boolean', 'description': '是否临时记录,必传,如果是批量提交,不能同时包含临时记录和非临时记录'}}, 'title': 'CreateCartItemParam'}}}}]

DeepDiff(record, body, ignore_order=True, report_repetition=True)

return {}, but __ref value have changed, if not using ignore_order,found diff value

OS, DeepDiff version and Python version (please complete the following information):

seperman commented 4 years ago

Hi @JeffXue Private variables that start with __ are ignored.

seperman commented 4 years ago

Actually you are right. It is a bug @JeffXue

seperman commented 4 years ago

It is still for the same reason I mentioned above though. The DeepHash module ignores private variables. But that manifests only in DeepDiff when ignore_order=True. I need to either make DeepHash include private variables or make DeepDiff ignore private variables when ignore_order=False.

seperman commented 4 years ago

Hi @JeffXue DeepDiff 5 is finally here! And it has a new parameter that you can use: https://zepworks.com/deepdiff/5.0.0/ignore_types_or_values.html#ignore-private-variables

Closing this ticket. Thanks