#19362: Recursion error when deleting model object through admin
-------------------------------+---------------------------------------
Reporter: m3wolf | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 1.5-alpha-1
Severity: Normal | Resolution:
Keywords: python2.7.3 | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+---------------------------------------
Changes (by akaariai):
* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted
Comment:
I was able to reproduce similar stack trace with:
{{{
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
@python_2_unicode_compatible
class Foof(models.Model):
def __unicode__(self):
return unicode(self.id)
repr(Foof())
}}}
I don't get a similar stack trace if I define `__str__` instead of
`__unicode__` or if I don't have python_2_unicode_compatible.
I have also seen the same stack trace somewhere else, don't remember where
and why.
There seems to be something strange going on. In the following code
{{{
def __str__(self):
if not six.PY3 and hasattr(self, '__unicode__'):
return force_text(self).encode('utf-8')
}}}
if I replace the force_text(self) with `self.__unicode__()` then the
recursion goes away. But to me it seems calling the `__unicode__` method
is the only thing that force_text is actually doing (apart of a couple of
isinstance checks).
In any case it seems the `__unicode__` + force_text() form an endless loop
in some cases. I am marking this as accepted as it seems likely there is
something strange going on in here. Although it is possible this is some
kind of user error after all.
--
Ticket URL: <https://code.djangoproject.com/ticket/19362#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit https://groups.google.com/groups/opt_out.