Opened 6 years ago

Closed 6 years ago

Last modified 3 years ago

#10632 closed (worksforme)

rare bug with log deletion in admin

Reported by: sdfsdhgjkbmnmxc Owned by: nobody
Component: contrib.admin Version: master
Severity: Keywords: logging
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Admin interface. When we delete object with long unicode representation it may be wrong truncated: "object_repr[:200]" may intersect utf-8 pair bytes.
Next we have "'utf8' codec can't decode byte 0xd0 in position 199: unexpected end of data." error.

This is very rare bug, but today i have it.

Fix is one-line:
ModelAdmin.log_addition(), and ModelAdmin.log_change() has force_unicode inside:

object_repr     = force_unicode(object),

but ModelAdmin.log_deletion() hasn't force_unicode inside:

object_repr     = object_repr,

Change History (5)

comment:1 Changed 6 years ago by jacob

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

comment:2 Changed 6 years ago by ramiro

This could be an user error because object_repr is already the result of calling force_unicode() on the model instance being deleted before log_deletion() is called. Maybe the __unicode__() model method provided by the user isn't returning an Unicode string?.

OTOH, we seem to be already being permissive with this error because we are calling force_unicode() twice when showing the message to the user: http://code.djangoproject.com/browser/django/trunk/django/contrib/admin/options.py?rev=10314#L1005

comment:3 Changed 6 years ago by mtredinnick

Ramiro: the reason for the force_unicode() calls that you point to is just historical due to the unicode and newforms-admin branches being done in parallel. We can remove the latter one at some point.

That being said, I agree with you about the log_deletion() case. I can't see how this can be happening and attempting to repeat it with something with a UTF-8 representation around 1000 bytes didn't repeat it (I was using chinese characters and various offsets, so it should have been triggered).

For the original reporter: what version of Python and Django were you using when you triggered this problem?

comment:4 Changed 6 years ago by jacob

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

Marking worksforme per Malcolm; please reopen with more info if someone else can reproduce.

comment:5 Changed 3 years ago by jacob

  • milestone 1.1 deleted

Milestone 1.1 deleted

Note: See TracTickets for help on using tickets.
Back to Top