Skip to content

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

Closed

Description

@amol-

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.

Activity

  1. digitalresistor commented on Jan 9, 2017

    @digitalresistor
    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.

  2. digitalresistor commented on Jan 17, 2017

    @digitalresistor
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions