noirbizarre / flask-restplus

Fully featured framework for fast, easy and documented API development with Flask
http://flask-restplus.readthedocs.org
Other
2.73k stars 506 forks source link

[ latest release of flask-restplus] AttributeError: 'Namespace' object has no attribute '__schema__' #537

Open 10000TB opened 5 years ago

10000TB commented 5 years ago

I have seen following issues with latest version of flask_restplus. While reverting back to 0.11.0, there is not issue with same code. I have seen people complaining about similar issue in the past for rest-plus, and notice that there were some new code went in regarding the schema attribute for api.py, which might have caused this. So want to share what I ran into, below is the direct trace I have:

api_1       | Exception on /api/v1/swagger.json [GET]
api_1       | Traceback (most recent call last):
api_1       |   File "/usr/lib/python3.6/site-packages/flask_restplus/api.py", line 215, in __getattr__
api_1       |     return getattr(self.default_namespace, name)
api_1       | AttributeError: 'Namespace' object has no attribute '__schema__'
api_1       |
api_1       | During handling of the above exception, another exception occurred:
api_1       |
api_1       | Traceback (most recent call last):
api_1       |   File "/usr/lib/python3.6/site-packages/flask/app.py", line 1813, in full_dispatch_request
api_1       |     rv = self.dispatch_request()
api_1       |   File "/usr/lib/python3.6/site-packages/flask/app.py", line 1799, in dispatch_request
api_1       |     return self.view_functions[rule.endpoint](**req.view_args)
api_1       |   File "/usr/lib/python3.6/site-packages/flask_restplus/api.py", line 325, in wrapper
api_1       |     resp = resource(*args, **kwargs)
api_1       |   File "/usr/lib/python3.6/site-packages/flask/views.py", line 88, in view
api_1       |     return self.dispatch_request(*args, **kwargs)
api_1       |   File "/usr/lib/python3.6/site-packages/flask_restplus/resource.py", line 44, in dispatch_request
api_1       |     resp = meth(*args, **kwargs)
api_1       |   File "/usr/lib/python3.6/site-packages/flask_restplus/api.py", line 808, in get
api_1       |     schema = self.api.__schema__
api_1       |   File "/usr/lib/python3.6/site-packages/flask_restplus/api.py", line 217, in __getattr__
api_1       |     raise AttributeError('Api does not have {0} attribute'.format(name))
api_1       | AttributeError: Api does not have __schema__ attribute
zedrdave commented 5 years ago

Did you find a fix for this? I am running into the exact same problem (took me way longer to debug too, as the app would only return a barebone "Internal error" JSON message)…

Update: my problem was (unsurprisingly) caused by the patched version of flask-restplus… Guess it's time to move to a cleaner solution to support Marshmallow/Webargs…

10000TB commented 5 years ago

didn't find a direct fix to the problem. But switching back to an earlier version of flask-restplus, which I was using fixed for me.