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

RuntimeError: The @response decorator cannot handle Response objects. #82

Open
cheizer opened this issue Jul 25, 2023 · 3 comments
Open
Labels
question Further information is requested

Comments

@cheizer
Copy link

cheizer commented Jul 25, 2023

Hello,
How can I drill down in to the error to figure out what is going on. The API works and then all of a sudden I see this error in the logs. I'm trying to figure out if it's my code or not.

Thanks,

[2023-07-25 09:31:54 -0700] [5810] [ERROR] Error handling request /api/xstate/bulk Traceback (most recent call last): File "/opt/theFairy/env/api/lib/python3.9/site-packages/gunicorn/workers/base_async.py", line 41, in handle self.handle_request(listener_name, req, client, addr) File "/opt/theFairy/env/api/lib/python3.9/site-packages/gunicorn/workers/ggevent.py", line 127, in handle_request super().handle_request(listener_name, req, sock, addr) File "/opt/theFairy/env/api/lib/python3.9/site-packages/gunicorn/workers/base_async.py", line 108, in handle_request respiter = self.wsgi(environ, resp.start_response) File "/opt/theFairy/env/api/lib/python3.9/site-packages/flask/app.py", line 2548, in __call__ return self.wsgi_app(environ, start_response) File "/opt/theFairy/env/api/lib/python3.9/site-packages/flask/app.py", line 2528, in wsgi_app response = self.handle_exception(e) File "/opt/theFairy/env/api/lib/python3.9/site-packages/flask_cors/extension.py", line 165, in wrapped_function return cors_after_request(app.make_response(f(*args, **kwargs))) File "/opt/theFairy/env/api/lib/python3.9/site-packages/flask/app.py", line 2525, in wsgi_app response = self.full_dispatch_request() File "/opt/theFairy/env/api/lib/python3.9/site-packages/flask/app.py", line 1822, in full_dispatch_request rv = self.handle_user_exception(e) File "/opt/theFairy/env/api/lib/python3.9/site-packages/flask_cors/extension.py", line 165, in wrapped_function return cors_after_request(app.make_response(f(*args, **kwargs))) File "/opt/theFairy/env/api/lib/python3.9/site-packages/flask/app.py", line 1820, in full_dispatch_request rv = self.dispatch_request() File "/opt/theFairy/env/api/lib/python3.9/site-packages/flask/app.py", line 1796, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) File "/opt/theFairy/env/api/lib/python3.9/site-packages/apifairy/decorators.py", line 96, in _response raise RuntimeError( RuntimeError: The @response decorator cannot handle Response objects.

@miguelgrinberg
Copy link
Owner

miguelgrinberg commented Jul 25, 2023

The error message tells you what's wrong:

The @response decorator cannot handle Response objects.

Fix your endpoint so that it returns the object referenced in the @response decorator to address this problem. Returning a Response object from Flask is not supported because that makes it impossible to do serialization with your Marshmallow schema.

@miguelgrinberg miguelgrinberg added the question Further information is requested label Jul 25, 2023
@cheizer
Copy link
Author

cheizer commented Jul 25, 2023

My Schema is super simple and generic.

class BulkStateSchema(ma.Schema): data = JSON()

and my result is

return {"data": {}}, 201

@miguelgrinberg
Copy link
Owner

@cheizer I think that is what you expect, but the error message indicates that in that particular instance a Response object was returned instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants