Dessia-tech / dessia_common

GNU Lesser General Public License v2.1
1 stars 2 forks source link

Bug ref: Cycles in jsonpointers not handled #630

Closed younesdessia closed 1 year ago

younesdessia commented 1 year ago

**Note: for support questions, please use https://nextcloud.dessia.tech/call/hr9z9bif

I have an object which has a list of Point3D as an attribute, when two or more points are equal, I have a problem with the to_dict (_check_platform).

NOTE: I think that we never entered this condition to trigger the error.

obj_._check_platform() Checking serialization process... Serialized. Deserializing... ['#/list_point/2'] Traceback (most recent call last): File "/home/younes/.local/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 3442, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "<ipython-input-3-f52ad432efb9>", line 1, in <module> obj_._check_platform() File "/home/younes/Bureau/DESSIA_WORK/dessia_common/dessia_common/core.py", line 495, in _check_platform return self.check_platform().raise_if_above_level(level=level) File "/home/younes/Bureau/DESSIA_WORK/dessia_common/dessia_common/core.py", line 499, in check_platform serializable_results = dcc.check_serialization_process(object_=self, use_pointers=True) File "/home/younes/Bureau/DESSIA_WORK/dessia_common/dessia_common/checks.py", line 177, in check_serialization_process deserialized_object = object_.dict_to_object(decoded_json) File "/home/younes/Bureau/DESSIA_WORK/dessia_common/dessia_common/serialization.py", line 72, in dict_to_object return dict_to_object(dict_=dict_, force_generic=force_generic, global_dict=global_dict, File "/home/younes/Bureau/DESSIA_WORK/dessia_common/dessia_common/serialization.py", line 307, in dict_to_object global_dict, pointers_memo = update_pointers_data(global_dict=global_dict, current_dict=dict_, File "/home/younes/Bureau/DESSIA_WORK/dessia_common/dessia_common/serialization.py", line 630, in update_pointers_data pointers_memo.update(dereference_jsonpointers(current_dict)) File "/home/younes/Bureau/DESSIA_WORK/dessia_common/dessia_common/serialization.py", line 671, in dereference_jsonpointers order = deserialization_order(dict_) File "/home/younes/Bureau/DESSIA_WORK/dessia_common/dessia_common/serialization.py", line 644, in deserialization_order raise NotImplementedError('Cycles in jsonpointers not handled') NotImplementedError: Cycles in jsonpointers not handled

in the json we can clearly see that the reference of the 3rd point is not clearly indicated (file: obj_list_point_bug) with this PR this is fixed https://github.com/Dessia-tech/dessia_common/pull/629 (file: obj_list_point)

-- Exemple to reproduce the bug:

`from typing import List

import volmdlr from dessia_common.core import DessiaObject

class ToDictTest(DessiaObject):

def __init__(self, list_point: List[volmdlr.Point3D], name: str = ""):
    self.list_point = list_point
    DessiaObject.__init__(self, name=name)

from dev import ToDictTest import volmdlr

pt_1 = volmdlr.Point3D(0, 1, 3) pt_2 = volmdlr.Point3D(1, 2, 5) pt_3 = volmdlr.Point3D(0, 1, 3)

obj_ = ToDictTest(list_point=[pt_1, pt_2, pt_3]) `

obj_list_point.json obj_list_point_bug.json