You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
:ref:`delta_serializer_label` is the function to serialize the delta content into a format that can be stored. The default is the pickle_dump function that comes with DeepDiff.
29
29
30
30
log_errors : Boolean, default=True
31
-
Whether to log the errors or not.
31
+
Whether to log the errors or not when applying the delta object.
32
+
33
+
raise_errors : Boolean, default=False
34
+
:ref:`raise_errors_label`
35
+
Whether to raise errors or not when applying a delta object.
32
36
33
37
mutate : Boolean, default=False.
34
38
:ref:`delta_mutate_label` defines whether to mutate the original object when adding the delta to it or not.
Now let's apply the delta to a very different object:
259
+
260
+
>>> t3 = [1, 2, 3, 5]
261
+
>>> t4 = t3 + delta
262
+
Unable to get the item at root[2][1]
263
+
264
+
We get the above log message that it was unable to get the item at root[2][1]. We get the message since by default log_errors=True
265
+
266
+
Let's see what t4 is now:
267
+
268
+
>>> t4
269
+
[3, 2, 3, 5]
270
+
271
+
So the delta was partially applied on t3.
232
272
233
-
>>>
273
+
Now let's set the raise_errors=True
274
+
275
+
>>> delta2 = Delta(diff, raise_errors=True)
276
+
>>>
277
+
>>> t3 + delta2
278
+
Unable to get the item at root[2][1]
279
+
Traceback (most recent call last):
280
+
current_old_value = obj[elem]
281
+
TypeError: 'int' object is not subscriptable
282
+
During handling of the above exception, another exception occurred:
283
+
deepdiff.delta.DeltaError: Unable to get the item at root[2][1]
234
284
235
285
236
286
.. _delta_safe_to_import_label:
237
287
238
288
Delta Safe To Import parameter
239
289
------------------------------
240
290
291
+
safe_to_import : Set, default=None.
292
+
safe_to_import is a set of modules that needs to be explicitly white listed to be loaded
293
+
Example: {'mymodule.MyClass', 'decimal.Decimal'}
294
+
Note that this set will be added to the basic set of modules that are already white listed.
295
+
296
+
297
+
As noted in :ref:`delta_dump_safety_label` and :ref:`delta_deserializer_label`, DeepDiff's Delta takes safety very seriously and thus limits the globals that can be deserialized when importing. However on occasions that you need a specific type (class) that needs to be used in delta objects, you need to pass it to the Delta via safe_to_import parameter.
298
+
299
+
The set of what is already white listed can be found in deepdiff.serialization.SAFE_TO_IMPORT
300
+
At the time of writing this document, this list consists of:
301
+
302
+
>>> from deepdiff.serialization importSAFE_TO_IMPORT
303
+
>>> from pprint import pprint
304
+
>>> pprint(SAFE_TO_IMPORT)
305
+
{'builtins.None',
306
+
'builtins.bin',
307
+
'builtins.bool',
308
+
'builtins.bytes',
309
+
'builtins.complex',
310
+
'builtins.dict',
311
+
'builtins.float',
312
+
'builtins.frozenset',
313
+
'builtins.int',
314
+
'builtins.list',
315
+
'builtins.range',
316
+
'builtins.set',
317
+
'builtins.slice',
318
+
'builtins.str',
319
+
'builtins.tuple',
320
+
'collections.namedtuple',
321
+
'datetime.datetime',
322
+
'datetime.time',
323
+
'datetime.timedelta',
324
+
'decimal.Decimal',
325
+
'deepdiff.helper.OrderedDictPlus',
326
+
'ordered_set.OrderedSet',
327
+
're.Pattern'}
328
+
329
+
If you want to pass any other argument to safe_to_import, you will need to put the full path to the type as it appears in the sys.modules
330
+
331
+
For example let's say you have a package call mypackage and has a module called mymodule. If you check the sys.modules, the address to this module must be mypackage.mymodule. In order for Delta to be able to serialize this object, first of all it has to be `picklable <https://docs.python.org/3/library/pickle.html#object.__reduce__>`_. Then you can pass:
verify_symmetry is used to verify that the original value of items are the same as when the delta was created. Note that in order for this option to work, the delta object will need to store more data and thus the size of the object will increase. Let's say that the diff object says root[0] changed value from X to Y. If you create the delta with the default value of verify_symmetry=False, then what delta will store is root[0] = Y. And if this delta was applied to an object that has any root[0] value, it will still set the root[0] to Y. However if verify_symmetry=True, then the delta object will store also that the original value of root[0] was X and if you try to apply the delta to an object that has root[0] of any value other than X, it will notify you.
Expected the old value for root[0] to be 1 but it is 3. Error found on: while checking the symmetry of the delta. You have applied the delta to an object that has different values than the original object the delta was made from
355
+
>>> t4
356
+
[2]
357
+
358
+
And if you had set raise_errors=True, then it would have raised the error in addition to logging it.
0 commit comments