[Django 1.7] horizon table summation can raise TypeError
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
OpenStack Dashboard (Horizon) |
Fix Released
|
Medium
|
Akihiro Motoki |
Bug Description
https:/
With Django 1.7, the unit tests fail with the following error.
It is one of work towards django 1.7.
"average": lambda data: sum(data, 0.0) / len(data)
TypeError: unsupported operand type(s) for +: 'float' and 'str'
With Django 1.6, the template code that looked up the variable behind
get_summation was catching the TypeError exception:
try: # method call (assuming no args required)
current = current()
except TypeError: # arguments *were* required
# GOTCHA: This will also catch any TypeError
# raised in the function itself.
current = settings.
With Django 1.7, the code has been refined to catch the exception only
when the function really requires argument (which get_summation()
doesn't):
try: # method call (assuming no args required)
current = current()
except TypeError:
try:
except TypeError: # arguments *were* required
current = settings.
else:
raise
Note that we need to install Django 1.7rc2 to reproduce this.
So instead of blindly relying on sum(), I introduced a safe_sum() and
safe_average() functions which mimick the behaviour we got with Django
1.6 by returning an empty string when we have invalid input data.
description: | updated |
Changed in horizon: | |
assignee: | nobody → Akihiro Motoki (amotoki) |
status: | New → In Progress |
Changed in horizon: | |
importance: | Undecided → Medium |
milestone: | none → juno-3 |
Changed in horizon: | |
milestone: | juno-3 → juno-rc1 |
Changed in horizon: | |
status: | Fix Committed → Fix Released |
Changed in horizon: | |
milestone: | juno-rc1 → 2014.2 |
Reviewed: https:/ /review. openstack. org/111932 /git.openstack. org/cgit/ openstack/ horizon/ commit/ ?id=d9c8a2e62fb f620eef4d1bdb29 2cb6ca6b830f17
Committed: https:/
Submitter: Jenkins
Branch: master
commit d9c8a2e62fbf620 eef4d1bdb292cb6 ca6b830f17
Author: Akihiro Motoki <email address hidden>
Date: Wed Aug 13 04:05:11 2014 +0900
Handle TypeError from table column summation code
This commit catches TypeError from horizon. tables. Column
summation calculation. This TypeError is caught inside Django
until Django 1.6, but Django 1.7 code is refined to catch
more specific case and it leads to horizon unit test failure.
Closes-Bug: #1355939 9880ccf117f2ea6 23fed466a44
Change-Id: I9d5b4565f1238a