Opened 9 years ago

Closed 6 years ago

Last modified 6 years ago

#4976 closed (fixed)

The contrib.humanize templatetags fail when given None.

Reported by: anonymous Owned by:
Component: Contrib apps Version: master
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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 9 years ago.
humanize.diff (3.4 KB) - added by Simon G. <dev@…> 9 years ago.
humainze-none.diff (3.3 KB) - added by Adam Vandenberg 6 years ago.
Updated patch to trunk

Download all attachments as: .zip

Change History (12)

Changed 9 years ago by anonymous

comment:1 Changed 9 years ago by Simon G. <dev@…>

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
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.

Changed 9 years ago by Simon G. <dev@…>

Attachment: humanize.diff added

comment:2 Changed 9 years ago by Jacob

Triage Stage: Design decision neededAccepted

comment:3 Changed 7 years ago by anonymous

Owner: changed from nobody to Alex Robbins

comment:4 Changed 6 years ago by Adam Nelson

Patch needs improvement: set

Some of these changes are already in trunk.

comment:5 Changed 6 years ago by Alex Robbins

Owner: Alex Robbins deleted

Changed 6 years ago by Adam Vandenberg

Attachment: humainze-none.diff added

Updated patch to trunk

comment:6 Changed 6 years ago by Adam Vandenberg

Patch needs improvement: unset

comment:7 Changed 6 years ago by Jannis Leidel

Triage Stage: AcceptedReady for checkin

comment:8 Changed 6 years ago by Jannis Leidel

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 Changed 6 years ago by Jannis Leidel

(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