Opened 17 years ago

Closed 14 years ago

Last modified 14 years ago

#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)

humanize_ordinal_TypeError_patch.diff (569 bytes ) - added by anonymous 17 years ago.
humanize.diff (3.4 KB ) - added by Simon G. <dev@…> 17 years ago.
humainze-none.diff (3.3 KB ) - added by Adam Vandenberg 14 years ago.
Updated patch to trunk

Download all attachments as: .zip

Change History (12)

by anonymous, 17 years ago

comment:1 by Simon G. <dev@…>, 17 years ago

Summary: The ordinal (contrib.humanize) templatetag fails when passing in NoneThe contrib.humanize templatetags fail when given None.
Triage Stage: UnreviewedDesign decision needed

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.

by Simon G. <dev@…>, 17 years ago

Attachment: humanize.diff added

comment:2 by Jacob, 17 years ago

Triage Stage: Design decision neededAccepted

comment:3 by anonymous, 15 years ago

Owner: changed from nobody to Alex Robbins

comment:4 by Adam Nelson, 14 years ago

Patch needs improvement: set

Some of these changes are already in trunk.

comment:5 by Alex Robbins, 14 years ago

Owner: Alex Robbins removed

by Adam Vandenberg, 14 years ago

Attachment: humainze-none.diff added

Updated patch to trunk

comment:6 by Adam Vandenberg, 14 years ago

Patch needs improvement: unset

comment:7 by Jannis Leidel, 14 years ago

Triage Stage: AcceptedReady for checkin

comment:8 by Jannis Leidel, 14 years ago

Resolution: fixed
Status: newclosed

(In [15000]) Fixed #4976 -- Stopped humanize template tags to raise a TypeError if passed a value of None. Thanks, Simon G. and Adam Vandenberg.

comment:9 by Jannis Leidel, 14 years ago

(In [15004]) [1.2.X] Fixed #4976 -- Stopped humanize template tags to raise a TypeError if passed a value of None. Thanks, Simon G. and Adam Vandenberg.

Backport from trunk (r15000).

Note: See TracTickets for help on using tickets.
Back to Top