FreeCAD-Gridfinity-Workbench icon indicating copy to clipboard operation
FreeCAD-Gridfinity-Workbench copied to clipboard

Object of type ViewProviderDocumentObject is not JSON serializable

Open mjskier opened this issue 1 year ago • 2 comments

On version 0.21.2 of FreeVAD, on both macos and linux, I get this traceback every time I save the document. I also get it randomly, which I assume is when freeCAD auto saves.

This doesn't seem to break anything, as the document saves fine and I'm able to export it to 3d print it. But obviously it pollutes the report view, and makes it hard to see potentially serious errors.

` 09:38:27 PropertyPythonObject::toString(): failed for <class 'freecad.gridfinity_workbench.commands.ViewProviderGridfinity'> 09:38:27 Traceback (most recent call last): File "/Applications/FreeCAD.app/Contents/Resources/lib/python3.10/json/init.py", line 231, in dumps return _default_encoder.encode(obj) File "/Applications/FreeCAD.app/Contents/Resources/lib/python3.10/json/encoder.py", line 199, in encode chunks = self.iterencode(o, _one_shot=True) File "/Applications/FreeCAD.app/Contents/Resources/lib/python3.10/json/encoder.py", line 257, in iterencode return _iterencode(o, 0) File "/Applications/FreeCAD.app/Contents/Resources/lib/python3.10/json/encoder.py", line 179, in default raise TypeError(f'Object of type {o.class.name} ' <class 'TypeError'>: Object of type ViewProviderDocumentObject is not JSON serializable

`

mjskier avatar Aug 03 '24 15:08 mjskier

I unfortunately do not have a macOS or Linux machine to test on. I don't currently know what might be causing this but I will keep it in mind.

Stu142 avatar Aug 04 '24 20:08 Stu142

I'll try to look into it. That's a good excuse for me to try to understand FreeCAD internals. Since it occurs when saving, I assume FreeCAD tries to serialize the object so it can write it out, and either it, or some object contained inside it is missing a function. Kind of odd it doesn't happen on Windows, but maybe the FreeCAD Python on Windows is packaged differently and has defaults that are not available in Linux/macOS

mjskier avatar Aug 04 '24 23:08 mjskier

Using Gridfinity Workbench Version 0.5.0 and FreeCAD 0.21.2 I could reproduce this problem on Windows as well:

19:41:13  PropertyPythonObject::toString(): failed for <class 'freecad.gridfinity_workbench.commands.ViewProviderGridfinity'>
19:41:13  Traceback (most recent call last):
  File "E:\Program Files\FreeCAD 0.21\bin\lib\json\__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "E:\Program Files\FreeCAD 0.21\bin\lib\json\encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "E:\Program Files\FreeCAD 0.21\bin\lib\json\encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "E:\Program Files\FreeCAD 0.21\bin\lib\json\encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
<class 'TypeError'>: Object of type ViewProvider is not JSON serializable

FlashSystems avatar Sep 05 '24 17:09 FlashSystems

It appears the section of code it is referencing I copied from the FreeCAD gear workbench and don't really know the ins and outs of it. All of the view related stuff.

I'll have a bit of a closer look and keep it in mind but unfortunately I just don't know, sorry.

Thanks for following up and maybe someone else might be able to weigh in at some point.

Stu142 avatar Sep 07 '24 12:09 Stu142

Probably related to this. (Looks specific to v0.21.2) https://forum.freecad.org/viewtopic.php?t=86423

mjskier avatar Sep 07 '24 17:09 mjskier

The traceback is gone with FreeCAD 1.0 RC1 So I think this issue can be closed as a regression specific to v0.21.2

mjskier avatar Sep 11 '24 14:09 mjskier

Thanks for following up, glad to hear it works in 1.0

Stu142 avatar Sep 15 '24 19:09 Stu142