kbwbe / A2plus

Another assembly workbench for FreeCAD, following and extending Hamish's Assembly 2 workbench
GNU Lesser General Public License v2.1
168 stars 69 forks source link

JSON serialisation error #613

Open glassondesignstudio opened 9 months ago

glassondesignstudio commented 9 months ago

After upgrading to 0.4.61 I found that there was a JSON serialization error occurring when I created the parts list. The error I am seeing is:

12:22:11 PropertyPythonObject::toString(): failed for <class 'a2p_importedPart_class.ImportedPartViewProviderProxy'> 12:22:11 Traceback (most recent call last): File "/usr/lib/python3.10/json/init.py", line 231, in dumps return _default_encoder.encode(obj) File "/usr/lib/python3.10/json/encoder.py", line 199, in encode chunks = self.iterencode(o, _one_shot=True) File "/usr/lib/python3.10/json/encoder.py", line 257, in iterencode return _iterencode(o, 0) File "/usr/lib/python3.10/json/encoder.py", line 179, in default raise TypeError(f'Object of type {o.class.name} ' <class 'TypeError'>: Object of type FeaturePython is not JSON serializable

This error doesn't seem to prevent parts lists being created but it might cause issues elsewhere. I have raised this separately because I don't think it is related to the parts list issue that I raised previously.

FreeCAD info:

[code] OS: KDE Flatpak runtime (KDE/plasma) Word size of FreeCAD: 64-bit Version: 0.21.2.33771 (Git) Build type: Release Branch: (HEAD detached at b9bfa5c) Hash: b9bfa5c5507506e4515816414cd27f4851d00489 Python 3.10.13, Qt 5.15.10, Coin 4.0.0, Vtk 8.2.0, OCC 7.6.3 Locale: English/Australia (en_AU) Installed mods:

simao commented 8 months ago

I am getting the same error when saving my assembly:

13:44:47  PropertyPythonObject::toString(): failed for <class 'a2p_importedPart_class.ImportedPartViewProviderProxy'>
13:44:47  Traceback (most recent call last):
  File "/usr/lib/python3.10/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib/python3.10/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.10/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python3.10/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
<class 'TypeError'>: Object of type FeaturePython is not JSON serializable
13:44:47  PropertyPythonObject::toString(): failed for <class 'a2p_importedPart_class.ImportedPartViewProviderProxy'>
13:44:47  Traceback (most recent call last):
  File "/usr/lib/python3.10/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib/python3.10/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.10/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python3.10/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
<class 'TypeError'>: Object of type FeaturePython is not JSON serializable
13:44:47  PropertyPythonObject::toString(): failed for <class 'a2p_importedPart_class.ImportedPartViewProviderProxy'>
13:44:47  Traceback (most recent call last):
  File "/usr/lib/python3.10/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib/python3.10/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.10/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python3.10/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
<class 'TypeError'>: Object of type FeaturePython is not JSON serializable
13:44:47  PropertyPythonObject::toString(): failed for <class 'a2p_importedPart_class.ImportedPartViewProviderProxy'>
13:44:47  Traceback (most recent call last):
  File "/usr/lib/python3.10/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib/python3.10/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.10/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python3.10/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
<class 'TypeError'>: Object of type FeaturePython is not JSON serializable
Syres916 commented 7 months ago

@kbwbe I've reported the issues with 0.21.2 https://forum.freecad.org/viewtopic.php?p=732345#p732345 and the fix has gone in to the 0.21 branch (it's already in 0.22dev main branch) with preparation for 0.21.3 but there's still an issue with this workbench for Python 3.11.x and above users which I'm happy to submit a Pull Request. Do you want PR's submitted against devel branch or master?

kbwbe commented 7 months ago

Thank you @Syres916 for help. Please submit the PR to master branch

IdahoEv commented 7 months ago

I get this same issue ("Object of type FeaturePython is not JSON serializable" errors in every attempt to save an a2plus file, one for each imported body) despite having FreeCAD 0.21.2, A2Plus 0.4.62, and Python 3.8. I can see that my version of a2p_importedPart_class.py on disk contains the updated code from PR #615. Am I missing something?

OS: Windows 11 build 22621
Word size of FreeCAD: 64-bit
Version: 0.21.2.33771 (Git)
Build type: Release
Branch: releases/FreeCAD-0-21
Hash: b9bfa5c5507506e4515816414cd27f4851d00489
Python 3.8.10, Qt 5.15.2, Coin 4.0.1, Vtk 8.2.0, OCC 7.6.3
Locale: English/United States (en_US)
Installed mods: 
  * A2plus 0.4.62
  * Assembly3 0.12.2
  * Assembly4 0.50.6
  * fasteners 0.4.63
  * FeedsAndSpeeds 0.5.0
  * Manipulator 1.5.7
  * woodworking 0.21.2.33771
Syres916 commented 7 months ago

@IdahoEv you can either use the latest 0.22dev build of FreeCAD or downgrade to 0.21.1, the fix for the core code will be available whenever 0.21.3 is released. Unfortunately 0.21.2 was released in a bit of a rush IMHO.