zope.testbrowser truncates document content after goBack()

Bug #98372 reported by Benji York
2
Affects Status Importance Assigned to Milestone
Launchpad itself
Invalid
Medium
Unassigned
Zope 3
Fix Released
Critical
Unassigned

Bug Description

in zope.testbrowser, under certain circumstances, after the .goBack() method is called the .contents attribute returns truncated HTML; reported by Roger Ineichen

Revision history for this message
Stephan Richter (srichter) wrote :

I can confirm that. It is probably a mechanize issue. I avoid the issue by doing reload(). ;-)

Revision history for this message
Stephan Richter (srichter) wrote :

Changes: submitter email, importance (medium => critical)

Revision history for this message
Marius Gedminas (mgedmin) wrote :

I think I found the bug:

* mechanize.Browser closes self._response and stashes it in its history list before opening a new page.

* self._response is ClientCookie._Util.response_seek_wrapper that wraps urllib.addinfourl that wraps socket._fileobject that wraps something (httplib.HTTPResponse perhaps?).

* response_seek_wrapper has a cache (a StringIO) that is stuffed with data read from the wrapped stream, so it can be re-read.

* response_seek_wrapper.close() closes the wrapped stream, and subsequent reads from that response_seek_wrapper read only the data that is already in the cache.

* hence truncation.

I added three lines to response_seek_wrapper.close():

            pos = self.tell()
            self.seek(0, 2)
            self.seek(pos)

just before it calls self.wrapper.close().

This fixes the problem for me

I'll leave it to someone more knowledgeable to decide whether this is the
proper fix and should be pushed into ClientCookie.

In the meantime a workaround is to do

   >>> whatever = len(browser.contents)

if you want to browser.goBack() to this page at some latter point

Revision history for this message
Marius Gedminas (mgedmin) wrote :

Changes: edited transcript, revised title

Revision history for this message
Benji York (benji) wrote :

This was fixed in revision 68784 by upgrading mechanize and can be resolved.

Revision history for this message
Fred Drake (fdrake) wrote :

Status: Pending => Resolved

Changed in launchpad:
importance: Undecided → Medium
status: Unconfirmed → Confirmed
Jonathan Knowles (jsk)
description: updated
Revision history for this message
Robert Collins (lifeless) wrote :

LP suffered this but worked around at the time; I'm sure we've updated zope.testbrowser since - and if not we're clearly not suffering now:)

Changed in launchpad:
status: Triaged → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.