Tox failing on py27dj14 environment

Bug #1273943 reported by Kirill Izotov
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Dashboard (Horizon)
Fix Released
Medium
Peter Belanyi

Bug Description

Full test log: http://paste.openstack.org/show/62066/

It seems like django.test.assertContain is unable to parse template html.

Further inspection revealed that there is a difference in parsing between start tag and end tag and even more, difference between parsing tags with and without the attributes:

HTMLParser.tagfind.match('<script>document.write("something")</script>', 1).end() would result in 7, so the parsed tag will be 'script'

but

HTMLParser.tagfind.match('<script type="text/javascript">document.write("something")</script>', 1).end() will result in 8 and a parsed tag of 'script ' (with tailing whitespace)

Somewhere between 2.7.3 and 2.7.4 Python had changed its HTMLParser.tagfind regex [1, 2]. Django relied heavily on this regex with its own _HtmlParser modification [3] and hadn't react fast enough to land the fix in 1.4 [4].

So what we are having here is for particular configuration including both python 2.7.4+ and django 1.4, django.test.assertContain would not be able to properly parse perfectly valid html and would fail this tests.

The question is what should we do in this case. Should we limit py27dj14 environment with basepython of 2.7.3, should we disable this tests on Django 1.4, replace the assertion function with one without the bug or just completely ignore that bug as irrelevant?

---

[1] http://hg.python.org/cpython/file/70274d53c1dd/Lib/HTMLParser.py#l25
[2] http://hg.python.org/cpython/file/026ee0057e2d/Lib/HTMLParser.py#l25
[3] https://github.com/django/django/blob/98a1e14e093211f15e91daa4c9de0402be5d31b8/django/utils/html_parser.py#L36-L39
[4] https://github.com/django/django/commit/6bc1b222994301782bd80780bdeec8c4eb44631a

Revision history for this message
Julie Pichon (jpichon) wrote :

Thank you for the detailed report and digging into the cause! We'll want to keep the tests for Django 1.4 as long as we support that version. It looks like we're fine for the py27dj14 gating tests for now, because the nodes run Ubuntu Precise and that ships with 2.7.3 - but this isn't an ideal situation and we'll want to fix the tests or test environment somehow.

Changed in horizon:
status: New → Confirmed
importance: Undecided → Medium
Revision history for this message
Peter Belanyi (pbelanyi) wrote :

I was thinking about possible solutions, and though I did not find a way to fix the tests, I did find a fix for the test environment. It seems a bit like a hack and I'm not sure it's the best way to fix the problem, so I wanted to check if it's worth the time to work more on it.

The basic idea is to modify the [testenv:py27dj14] case in tox.ini to include an extra command which would overwrite django/utils/html_parser.py with the version containing the patch for python 2.7.4 (if python is newer than 2.7.3).

Does it sound like an acceptable solution?

Peter Belanyi (pbelanyi)
Changed in horizon:
assignee: nobody → Peter Belanyi (pbelanyi)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to horizon (master)

Fix proposed to branch: master
Review: https://review.openstack.org/80990

Changed in horizon:
status: Confirmed → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to horizon (master)

Reviewed: https://review.openstack.org/80990
Committed: https://git.openstack.org/cgit/openstack/horizon/commit/?id=b4934d17e00aa88c508a901e912d56d60b6f39d8
Submitter: Jenkins
Branch: master

commit b4934d17e00aa88c508a901e912d56d60b6f39d8
Author: Peter Belanyi <email address hidden>
Date: Mon Mar 17 15:41:04 2014 +0100

    Patch Django 1.4 on Python 2.7.4 or greater

    This fix provides a patch for Django 1.4 to get rid of
    the issues with django.test.assertContains in the py27dj14
    test environment.

    Change-Id: I4c7a225ef1095999f7c109e77c95e1a6fe04db8c
    Closes-Bug: #1273943

Changed in horizon:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in horizon:
milestone: none → juno-1
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in horizon:
milestone: juno-1 → 2014.2
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.