Skip to content

BaseType's has no attribute 'model_class' #607

Open
@ceandrade

Description

@ceandrade

I copied a simple code from https://gist.github.com/voidfiles/5c70471450ee476796c7, to extract a JSON schema for Swagger. It turned out that the code does not run properly. SO, I did some debugging and I found that the property 'model_class' for lists are not working. This is some code for debugging:

from schematics.types import StringType, IntType
from schematics.types.compound import ListType

my_list = ListType(IntType, required=True, min_size=1)
print(my_list.model_class)
$ python test.py 
Traceback (most recent call last):
  File "test.py", line 6, in <module>
    print(my_list.model_class)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/schematics/types/compound.py", line 197, in model_class
    return self.field.model_class
AttributeError: 'IntType' object has no attribute 'model_class'

Indeed, this also happend for any BaseType, for nested lists, and so. For example:

from schematics.types import StringType, IntType
from schematics.types.compound import ListType

my_list = ListType(ListType(ListType(IntType)), required=True, min_size=1)

print(my_list.model_class)
$ python test.py 
Traceback (most recent call last):
  File "test.py", line 6, in <module>
    print(my_list.model_class)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/schematics/types/compound.py", line 197, in model_class
    return self.field.model_class
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/schematics/types/compound.py", line 197, in model_class
    return self.field.model_class
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/schematics/types/compound.py", line 197, in model_class
    return self.field.model_class
AttributeError: 'IntType' object has no attribute 'model_class'

This is another weird behaviour. Since we have nested listed, should 'model_class' return 'ListType' (or 'ListType(ListType(IntTyoe))') when called in the most external container? Why do we recurse here?

Should we implement 'model_class' for all BaseType's?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions