biosustain / potion

Flask-Potion is a RESTful API framework for Flask and SQLAlchemy, Peewee or MongoEngine
http://potion.readthedocs.io
Other
488 stars 51 forks source link

example `peewee_simple.py` won't run (`AttributeError: 'Metadata' object has no attribute 'rel'`) #179

Open maxbellec opened 5 years ago

maxbellec commented 5 years ago

by running the example peewee_simple.py as is, I get

$ python peewee_simple.py
Traceback (most recent call last):
  File "peewee_simple.py", line 42, in <module>
    api.add_resource(BookResource)
  File "/home/m/.local/share/virtualenvs/pano-vehicle-version-config-api-JCsed19j/lib/python3.6/site-packages/flask_potion/__init__.py", line 215, in add_resource
    resource.manager = self.default_manager(resource, resource.meta.get('model'))
  File "/home/m/.local/share/virtualenvs/pano-vehicle-version-config-api-JCsed19j/lib/python3.6/site-packages/flask_potion/contrib/peewee/manager.py", line 26, in __init__
    super(PeeweeManager, self).__init__(resource, model)
  File "/home/m/.local/share/virtualenvs/pano-vehicle-version-config-api-JCsed19j/lib/python3.6/site-packages/flask_potion/manager.py", line 27, in __init__
    self._init_model(resource, model, resource.meta)
  File "/home/m/.local/share/virtualenvs/pano-vehicle-version-config-api-JCsed19j/lib/python3.6/site-packages/flask_potion/contrib/peewee/manager.py", line 63, in _init_model
    if column.primary_key or name in model._meta.rel:
AttributeError: 'Metadata' object has no attribute 'rel'
maxbellec commented 5 years ago

maybe this is linked to https://github.com/biosustain/potion/issues/133? By changing

if column.primary_key or name in model._meta.rel: to if column.primary_key or name in model._meta.refs:, it fixes the error.