miguelgrinberg / turbo-flask

Integration of Hotwire's Turbo library with Flask.
MIT License
301 stars 35 forks source link

Werkzeug Assertion Error in Logs #24

Open ntorba opened 2 years ago

ntorba commented 2 years ago

Hello,

I am seeing an error from Werkzeug in the logs of my application, but it doesn't seem to effect the functioning of my app (at least in what I've been working on so far..)

Here are the logs:

172.18.0.1 - - [04/Mar/2022 14:00:16] "GET /turbo-stream HTTP/1.1" 500 -
Error on request:
Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/werkzeug/serving.py", line 319, in run_wsgi
    execute(self.server.app)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/werkzeug/serving.py", line 313, in execute
    write(b"")
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/werkzeug/serving.py", line 259, in write
    assert status_set is not None, "write() before start_response"
AssertionError: write() before start_response

The app seems to function fine, I am getting a turbo frame (but I am not currently using streams or more advanced features, so I might notice the issue when I get there)

Has anyone else seen this?

Thanks

miguelgrinberg commented 2 years ago

Are you using latest versions of all the related packages? turbo-flask, flask-sock, simple-websocket, flask, werkzeug.

yalattas commented 2 years ago

In my case. I seen this error and thought that I mis-configured flask as I am putting fundamental design pattern wsgi -> url -> controller -> ... -> model

flask_app  | 172.18.0.1 - - [15/Jun/2022 10:10:41] "GET /test HTTP/1.1" 500 -
flask_app  | Error on request:
flask_app  | Traceback (most recent call last):
flask_app  |   File "/var/lang/lib/python3.9/site-packages/werkzeug/serving.py", line 324, in run_wsgi
flask_app  |     execute(self.server.app)
flask_app  |   File "/var/lang/lib/python3.9/site-packages/werkzeug/serving.py", line 316, in execute
flask_app  |     write(data)
flask_app  |   File "/var/lang/lib/python3.9/site-packages/werkzeug/serving.py", line 264, in write
flask_app  |     assert status_set is not None, "write() before start_response"
flask_app  | AssertionError: write() before start_response

Turns out, I missed importing json while I was using it in return

Resolved just by adding import json

Not sure if it's going to help you or not. But I hope it give you a perspective

kmtnck commented 6 months ago

I notice me too this error on development wekzeug during a disconnection. Seems that there is a race condition during an assertion on write() method. The slang "assert" suggest me that is a test unit or similar integrated into wekzeug server. This server its used only on development mode. My question is: are there some side effects during developing if I consider this error only a noise? so I can ignore without fear?

thank in advance

miguelgrinberg commented 5 months ago

are there some side effects during developing if I consider this error only a noise?

Aside from the annoyance of seeing the error I don't think there is any concern. You should definitely use a production server when you get to deploy this for real, Werkzeug should never be used in production.