Code

Opened 6 years ago

Closed 6 years ago

#7100 closed (invalid)

breadcrumb UnicodeEncodeError

Reported by: dvainsencher Owned by: nobody
Component: Core (Management commands) Version: master
Severity: Keywords: breadcrumbs
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Non ascii str string raise UnicodeEncodeError in breadcrumbs render in django/contrib/admin/templates/admin/change_form.html

14  {% if add %}{% trans "Add" %} {{ opts.verbose_name }}{% else %}{{ original|truncatewords:"18" }}{% endif %}

when editing an object.

I purpose change django/contrib/admin/views/main.py

403 - 'original': manipulator.original_object,
403 + 'original': smart_str(manipulator.original_object),

or, if original can't be changed, we can just add another variable in the Request

404 + 'original_str': smart_str(manipulator.original_object),

and change reference in the template - django/contrib/admin/templates/admin/change_form.html

14 - {% if add %}{% trans "Add" %} {{ opts.verbose_name }}{% else %}{{ original|truncatewords:"18" }}{% endif %}
14 + {% if add %}{% trans "Add" %} {{ opts.verbose_name }}{% else %}{{ original_str|truncatewords:"18" }}{% endif %}

Attachments (1)

defaultfilters.diff (1.2 KB) - added by dvainsencher 6 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 6 years ago by mtredinnick

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Next time, please attach a proper patch file, since it will include context in the even that line 402 or 403 changes before we get to the ticket.

This looks like a bug, but the proposed fix isn't the right approach. Instead, truncatewords should be fixed to work with unicode strings. And we don't need to go overboard here; we'll still consider "words" to be whitespace-separated sequences of characters, rather than teaching it to understand all the constraints of all the languages in the world.

comment:2 Changed 6 years ago by mtredinnick

  • Has patch unset

Changed 6 years ago by dvainsencher

comment:3 Changed 6 years ago by dvainsencher

Sorry by the missing patch. I tried other approach now as showed in the patch.

I'm still in doubt if the check for to_str in _dec function is really necessary, but i'm sure that for now it have little impact over other stringfunctions decorated functions.

comment:4 Changed 6 years ago by dvainsencher

There is also the workaround of use unicode function in the model but i think that a generic solution is better.

comment:5 Changed 6 years ago by Karen Tracey <kmtracey@…>

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

I've verified truncatewords handles unicode properly. The problem seems to be a Model that returns a non-ASCII data via an __str__() function instead of a __unicode__() function. Having a __unicode__ function in your model is not a workaround, it is the generic solution for having your models return non-ASCII representations of themselves. If I have misunderstood how you ran into this problem please reopen with specifics of the Model involved, data contained in it, and a traceback of the error you are seeing. The one I can recreate is definitely a user error of not having a __unicode__ method on a model that needs one.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.