Opened 8 years ago

Closed 4 years ago

Last modified 4 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 8 years ago.
humanize.diff (3.4 KB) - added by Simon G. <dev@…> 8 years ago.
humainze-none.diff (3.3 KB) - added by adamv 4 years ago.
Updated patch to trunk

Download all attachments as: .zip

Change History (12)

Changed 8 years ago by anonymous

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

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from The ordinal (contrib.humanize) templatetag fails when passing in None to The contrib.humanize templatetags fail when given None.
  • Triage Stage changed from Unreviewed to Design 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 8 years ago by Simon G. <dev@…>

comment:2 Changed 7 years ago by jacob

  • Triage Stage changed from Design decision needed to Accepted

comment:3 Changed 5 years ago by anonymous

  • Owner changed from nobody to alexr

comment:4 Changed 5 years ago by adamnelson

  • Patch needs improvement set

Some of these changes are already in trunk.

comment:5 Changed 5 years ago by alexr

  • Owner alexr deleted

Changed 4 years ago by adamv

Updated patch to trunk

comment:6 Changed 4 years ago by adamv

  • Patch needs improvement unset

comment:7 Changed 4 years ago by jezdez

  • Triage Stage changed from Accepted to Ready for checkin

comment:8 Changed 4 years ago by jezdez

  • Resolution set to fixed
  • Status changed from new to closed

(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 4 years ago by jezdez

(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