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

Seems WebOb 1.7 has some glitches with WebTest when a 204 is responded #305

Closed
amol- opened this issue Jan 8, 2017 · 2 comments
Closed

Comments

@amol-
Copy link
Contributor

amol- commented Jan 8, 2017

The recent WebOb 1.7 changes to initialisation function seem to had introduced a side effect when WebTest is used, as webtest will recreate a new Response object from the application response.

A simple testcase can be created to showcase the issue:

from webob import Response

def wsgi_app(environ, start_response):
    resp = Response(status='204 No Content', body=b'')
    resp.content_type = None
    return resp(environ, start_response)

The snippet is meant to work on both 1.6 and 1.7, so it adds some unnecessary values like body and content_type which are already provided in 1.7 (those values are in fact a nop on 1.7) while they are required on 1.6 to generate a response without content.

The response is as expected both on 1.6 and 1.7

Response: 204 No Content


Creating a plain webtest TestApp from the previous example:

from webtest import TestApp

app = TestApp(wsgi_app)
app.get('/')

will issue a validation error on WebOb 1.7:

Iterator garbage collected without being closedException AssertionError: AssertionError('Iterator garbage collected without being closed',) in <bound method IteratorWrapper.__del__ of <webtest.lint.IteratorWrapper object at 0x100ed0850>> ignored

while it will work without the error with WebOb 1.6.

This seems to be related to 35fd585 as https://github.com/Pylons/webob/blob/master/webob/response.py#L323 throws away the webtest IteratorWrapper injected by WebTest replacing it with [b''] as code_has_body is False and thus breaking WebTest

I wouldn't take for granted that if there is an app_iter it will be wrong and needs to be discarded as response has no content. It's probably a right assumption in the case of body, but discarding app_iter might in fact break some application by discarding an iterator which returns an empty response too but has other side effects.

@digitalresistor
Copy link
Member

Thanks for the report @amol-

It may be that if there is an app_iter provided that we set it explicitly, and let the user deal with the breakage if their app_iter contains data and it shouldn't.

@digitalresistor
Copy link
Member

I have added a test and app_iter is now set on Response. New release is out: https://pypi.python.org/pypi/WebOb/1.7.1

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

No branches or pull requests

2 participants