Opened 11 years ago
Closed 11 years ago
#21959 closed Bug (fixed)
widthratio templatetag fails to handle NaN ratio
Reported by: | rmoe | Owned by: | |
---|---|---|---|
Component: | Template system | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When value or max_value are float('inf') or float('nan') the ratio calculation can raise an exception.
Attachments (1)
Change History (5)
by , 11 years ago
Attachment: | defaulttags.diff added |
---|
comment:1 by , 11 years ago
comment:2 by , 11 years ago
You just need to call widthratio with float('inf') as both the value and max_value. like so:
{% widthratio 'inf' 'inf' 100 %}
Which will raise this (because ratio is NaN and can't be converted to an integer):
ValueError at /project/ cannot convert float NaN to integer Request Method: GET Django Version: 1.5.4 Exception Type: ValueError Exception Value: cannot convert float NaN to integer Exception Location: /usr/lib/python2.7/dist-packages/django/template/defaulttags.py in render, line 467
For some additional context, this was encountered in the Horizon component of the OpenStack project. https://github.com/openstack/horizon/blob/master/horizon/templates/horizon/common/_limit_summary.html#L6
When disabling quotas in the Nova component (the data it's trying to build the pie charts for) all quota values are set to -1 which equates to an infinite quota. So in the case where quotas are disabled usage.limits.totalInstancesUsed and usage.limits.maxTotalInstances are both float('inf'). This breaks the project overview page because of the exception raised from the widthratio templatetag.
comment:3 by , 11 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:4 by , 11 years ago
Owner: | set to |
---|---|
Resolution: | → fixed |
Status: | new → closed |
Hi, thanks for reporting. Do you mind giving more information on how to reproduce this exception so a newbie could partake? Thanks!