ShapeWorks icon indicating copy to clipboard operation
ShapeWorks copied to clipboard

Python import: DataAugmentationUtils -- pydantic errors

Open siboles opened this issue 10 months ago • 1 comments

Description

Importing DataAugmentationUtils raises a TypeError with classes inheriting from ApiModel. I was able to resolve the issue, but posting here in case others have the same problem.

Details

Release: v6.5.1 OS: PopOS 22.04

To Reproduce Error

import DataAugmentationUtils

Error Trace

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/scotts/miniforge3/envs/shapeworks/lib/python3.9/site-packages/DataAugmentationUtils/__init__.py", line 1, in <module>
    from DataAugmentationUtils import DataAugmentation
  File "/home/scotts/miniforge3/envs/shapeworks/lib/python3.9/site-packages/DataAugmentationUtils/DataAugmentation.py", line 6, in <module>
    from DataAugmentationUtils import Utils
  File "/home/scotts/miniforge3/envs/shapeworks/lib/python3.9/site-packages/DataAugmentationUtils/Utils.py", line 1, in <module>
    import shapeworks as sw
  File "/home/scotts/miniforge3/envs/shapeworks/lib/python3.9/site-packages/shapeworks/__init__.py", line 13, in <module>
    from .portal import download_dataset
  File "/home/scotts/miniforge3/envs/shapeworks/lib/python3.9/site-packages/shapeworks/portal.py", line 16, in <module>
    from swcc.models import Dataset
  File "/home/scotts/miniforge3/envs/shapeworks/lib/python3.9/site-packages/swcc/models/__init__.py", line 2, in <module>
    from .other_models import (
  File "/home/scotts/miniforge3/envs/shapeworks/lib/python3.9/site-packages/swcc/models/other_models.py", line 19, in <module>
    class Segmentation(ApiModel):
  File "pydantic/main.py", line 197, in pydantic.main.ModelMetaclass.__new__
  File "pydantic/fields.py", line 506, in pydantic.fields.ModelField.infer
  File "pydantic/fields.py", line 436, in pydantic.fields.ModelField.__init__
  File "pydantic/fields.py", line 552, in pydantic.fields.ModelField.prepare
  File "pydantic/fields.py", line 751, in pydantic.fields.ModelField._type_analysis
  File "pydantic/fields.py", line 808, in pydantic.fields.ModelField._create_sub_type
  File "pydantic/fields.py", line 436, in pydantic.fields.ModelField.__init__
  File "pydantic/fields.py", line 552, in pydantic.fields.ModelField.prepare
  File "pydantic/fields.py", line 668, in pydantic.fields.ModelField._type_analysis
  File "/home/scotts/miniforge3/envs/shapeworks/lib/python3.9/typing.py", line 852, in __subclasscheck__
    return issubclass(cls, self.__origin__)
TypeError: issubclass() arg 1 must be a class

My Fix

Updating pydantic from 1.10.7 (from release python_requirements.txt) to 1.10.13 seems to resolve the issue.

conda activate shapeworks
pip install pydantic==1.10.13

siboles avatar Mar 19 '25 18:03 siboles

Yes, this has been updated in the master branch and will be part of the next ShapeWorks release.

https://github.com/SCIInstitute/ShapeWorks/blob/ade743ba724a00a6c6e848ba56f46f13a435220a/python_requirements.txt#L136

akenmorris avatar Mar 20 '25 21:03 akenmorris