Opened 8 years ago

Closed 7 years ago

#3509 closed (invalid)

[patch] django.newforms.util.smart_unicode() is not smart enough :)

Reported by: Anton Khalikov <anton@…> Owned by: nobody
Component: Forms Version: master
Severity: Keywords:
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Guys

django.newforms.util.smart_unicode() needs to be smarter to don't unicode None, True and False values and leave them as they are.

The patch is attached.

Attachments (1)

smart_unicode_fix.patch (975 bytes) - added by Anton Khalikov <anton@…> 8 years ago.
Quick fix

Download all attachments as: .zip

Change History (6)

Changed 8 years ago by Anton Khalikov <anton@…>

Quick fix

comment:1 Changed 8 years ago by Anton Khalikov <anton@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from django.newforms.util.smart_unicode() is not smart enough :) to [patch] django.newforms.util.smart_unicode() is not smart enough :)

Sorry, forgot to name the subject properly.
As I always do :)

comment:2 Changed 8 years ago by SmileyChris

  • Triage Stage changed from Unreviewed to Design decision needed

It's true that something needs to change so that unicode(s, settings.DEFAULT_CHARSET) doesn't choke on these types, but smart_unicode looks like it should always return a unicode object. Perhaps just str(s) if it's type is NoneType or bool.

comment:3 Changed 8 years ago by Anton Khalikov <anton@…>

smart_unicode(None) -> u'None' -> try to save it in DB and guess what happened
same is for smart_unicode(True) -> u'True' -> same thing

comment:4 Changed 8 years ago by mtredinnick

Can you give an example of where the current behaviour is causing errors?

smart_unicode() is an equivalent of str() and unicode() in that it forces the result to be a string, intentionally. So not converting certain types is counter-intuitive behaviour.

Are there cases in the code where we are calling smart_unicode() on booleans or None and then expecting them to act as their original types? Those cases should be fixed, but the general fix in this ticket is not the right way to do it.

comment:5 Changed 7 years ago by Øyvind Saltvik <oyvind@…>

  • Resolution set to invalid
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.
Back to Top