#4976 closed (fixed)
The contrib.humanize templatetags fail when given None.
Reported by: | anonymous | Owned by: | |
---|---|---|---|
Component: | Contrib apps | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Calling django.contrib.humanize.templatetags.ordinal(None) raises an uncaught TypeError when casting None to an int.
The patch simply adds an exception handler for a TypeError, which behaves like the ValueError handler (returning the original arg untouched.)
The module lacked doctests, so I didn't add an ordinal(None) test.
Attachments (3)
Change History (12)
by , 17 years ago
Attachment: | humanize_ordinal_TypeError_patch.diff added |
---|
comment:1 by , 17 years ago
Summary: | The ordinal (contrib.humanize) templatetag fails when passing in None → The contrib.humanize templatetags fail when given None. |
---|---|
Triage Stage: | Unreviewed → Design decision needed |
by , 17 years ago
Attachment: | humanize.diff added |
---|
comment:2 by , 17 years ago
Triage Stage: | Design decision needed → Accepted |
---|
comment:3 by , 15 years ago
Owner: | changed from | to
---|
comment:4 by , 14 years ago
Patch needs improvement: | set |
---|
Some of these changes are already in trunk.
comment:5 by , 14 years ago
Owner: | removed |
---|
comment:6 by , 14 years ago
Patch needs improvement: | unset |
---|
comment:7 by , 14 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:8 by , 14 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:9 by , 14 years ago
Note:
See TracTickets
for help on using tickets.
Thanks for pointing this out.
The tests for humanize are in django/tests/regressiontests/humanize, but it looks like all the others in there will choke on None too. Whilst people probably shouldn't be passing invalid input to these, I've expanded your patch to cover these cases (and tests), and will let one of the core developers decide whether this is the right approach.