Opened 9 years ago

Closed 9 years ago

Last modified 7 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:


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 9 years ago by Jacob

milestone: 1.1
Triage Stage: UnreviewedAccepted

comment:2 Changed 9 years ago by Ramiro Morales

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:

comment:3 Changed 9 years ago by Malcolm Tredinnick

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 9 years ago by Jacob

Resolution: worksforme
Status: newclosed

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

comment:5 Changed 7 years ago by Jacob

milestone: 1.1

Milestone 1.1 deleted

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