dd-trace-py
dd-trace-py copied to clipboard
Flask streaming response missing close method
The addition of flask streaming support in #3826 introduced a bug with how response objects are handled. The response from the WSGI middleware (used in the implementation of the flask streaming feature) is a generator. However, PEP 333 specifies additionally that the iterable response can have a close() method which must be called by a server.
The lack of a close() method on the response results can cause unexpected failures with the test client, like the following with SQLAlchemy:
InvalidRequestError: Can't attach instance <User at 0x7fe7de23d410>; another instance with key (<class 'dw.user.User'>, (1016,), None) is already present in this session.
[18:13:22 UTC] [pytest:controller]
[18:13:22 UTC] [pytest:controller] existing_state = <sqlalchemy.orm.state.InstanceState object at 0x7fe7ddbaae10>
[18:13:22 UTC] [pytest:controller] key = (<class 'some_mode;.user.User'>, (1016,), None)
[18:13:22 UTC] [pytest:controller] o = User:[email protected]
[18:13:22 UTC] [pytest:controller] self = <sqlalchemy.orm.identity.WeakInstanceDict object at 0x7fe7ddd58a90>
[18:13:22 UTC] [pytest:controller] state = <sqlalchemy.orm.state.InstanceState object at 0x7fe7de23d8d0>
[18:13:22 UTC] [pytest:controller]
[18:13:22 UTC] [pytest:controller] /opt/dogweb/lib/python2.7/site-packages/sqlalchemy/orm/identity.py:150: InvalidRequestError