Opened 17 years ago

Closed 17 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: dev
Severity: Keywords:
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

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@…> 17 years ago.
Quick fix

Download all attachments as: .zip

Change History (6)

by Anton Khalikov <anton@…>, 17 years ago

Attachment: smart_unicode_fix.patch added

Quick fix

comment:1 by Anton Khalikov <anton@…>, 17 years ago

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

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

comment:2 by Chris Beaven, 17 years ago

Triage Stage: UnreviewedDesign 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 by Anton Khalikov <anton@…>, 17 years ago

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 by Malcolm Tredinnick, 17 years ago

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 by Øyvind Saltvik <oyvind@…>, 17 years ago

Resolution: invalid
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top