Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BaseType's has no attribute 'model_class' #607

Open
ceandrade opened this issue Dec 11, 2019 · 2 comments
Open

BaseType's has no attribute 'model_class' #607

ceandrade opened this issue Dec 11, 2019 · 2 comments
Labels

Comments

@ceandrade
Copy link

ceandrade commented Dec 11, 2019

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?

@ceandrade
Copy link
Author

ceandrade commented Dec 11, 2019

A simple is include 'model_class' property into BaseType's:

class BaseType(object):

    @property
    def model_class(self):
        return self.typeclass

But you have the recursive thing yet.

@lkraider
Copy link
Contributor

Only the ModelType should have model_class property.

It's probably a bug in ListType to assume its field has that property

return self.field.model_class

@lkraider lkraider added the bug label Aug 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants