[Django] #21198: @python_2_unicode_compatible, abstract models, working on 1.4 but causing infinite loop on 1.5.

7 views
Skip to first unread message

Django

unread,
Sep 30, 2013, 5:50:54 AM9/30/13
to django-...@googlegroups.com
#21198: @python_2_unicode_compatible, abstract models, working on 1.4 but causing
infinite loop on 1.5.
-------------------------------+--------------------
Reporter: jpic | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.5
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
On Django 1.4.2, I can call unicode(my_city) without any problem. my_city
being an instance of City defined here: https://github.com/yourlabs
/django-cities-light/blob/master/cities_light/models.py

As you can see:

- City inherits from Base abstract model,
- City is decorated by @python_2_unicode_compatible,
- Base is also decorated by @python_2_unicode_compatible,
- Base defines __str__
- City does not define __str__

When these conditions are met then Django 1.5 gets stuck in an infinite
loop. The solution is to remove @python_2_unicode_compatible decorator
from City.

Traceback: https://travis-ci.org/yourlabs/django-autocomplete-
light/jobs/11953680

I don't know if this a lack of documentation or a bug.

--
Ticket URL: <https://code.djangoproject.com/ticket/21198>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Sep 30, 2013, 5:58:20 AM9/30/13
to django-...@googlegroups.com
#21198: @python_2_unicode_compatible, abstract models, working on 1.4 but causing
infinite loop on 1.5.
---------------------------+------------------------------------
Reporter: jpic | Owner: nobody
Type: Bug | Status: new
Component: Utilities | Version: 1.5
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------+------------------------------------
Changes (by aaugustin):

* needs_better_patch: => 0
* component: Uncategorized => Utilities
* needs_tests: => 0
* needs_docs: => 0
* type: Uncategorized => Bug
* stage: Unreviewed => Accepted


Comment:

The documentation makes it clear that `@python_2_unicode_compatible` is
only intended for classes that have a `__str__` method.

https://docs.djangoproject.com/en/dev/ref/utils/#django.utils.encoding.python_2_unicode_compatible

Django's historical behavior of building `__str__` from `__unicode__` and
backwards-compatibility concerns make `@python_2_unicode_compatible` prone
to infinite recursion.

This is extremely hard to debug. It's impossible to print the object since
`unicode`, `str` and `repr` all go into infinite recursion. I'd like to
raise a better exception instead.

--
Ticket URL: <https://code.djangoproject.com/ticket/21198#comment:1>

Django

unread,
Sep 30, 2013, 9:25:53 AM9/30/13
to django-...@googlegroups.com
#21198: @python_2_unicode_compatible, abstract models, working on 1.4 but causing
infinite loop on 1.5.
---------------------------+------------------------------------
Reporter: jpic | Owner: nobody

Type: Bug | Status: new
Component: Utilities | Version: 1.5
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------+------------------------------------

Comment (by jpic):

Thanks for the link, but I don't get why that would work on Django 1.4.2
and not on Django 1.5.4.

--
Ticket URL: <https://code.djangoproject.com/ticket/21198#comment:2>

Django

unread,
Oct 2, 2013, 10:21:37 AM10/2/13
to django-...@googlegroups.com
#21198: @python_2_unicode_compatible, abstract models, working on 1.4 but causing
infinite loop on 1.5.
---------------------------+------------------------------------
Reporter: jpic | Owner: chmodas
Type: Bug | Status: assigned

Component: Utilities | Version: 1.5
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------+------------------------------------
Changes (by chmodas):

* owner: nobody => chmodas
* status: new => assigned


Comment:

PR - https://github.com/django/django/pull/1703

--
Ticket URL: <https://code.djangoproject.com/ticket/21198#comment:3>

Django

unread,
Oct 2, 2013, 4:15:12 PM10/2/13
to django-...@googlegroups.com
#21198: @python_2_unicode_compatible, abstract models, working on 1.4 but causing
infinite loop on 1.5.
---------------------------+-------------------------------------
Reporter: jpic | Owner: aaugustin

Type: Bug | Status: assigned
Component: Utilities | Version: 1.5
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------+-------------------------------------
Changes (by aaugustin):

* owner: chmodas => aaugustin


--
Ticket URL: <https://code.djangoproject.com/ticket/21198#comment:4>

Django

unread,
Oct 13, 2013, 11:59:29 AM10/13/13
to django-...@googlegroups.com
#21198: @python_2_unicode_compatible, abstract models, working on 1.4 but causing
infinite loop on 1.5.
---------------------------+-------------------------------------
Reporter: jpic | Owner: aaugustin
Type: Bug | Status: assigned
Component: Utilities | Version: 1.5
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------+-------------------------------------

Comment (by aaugustin):

#19362 was an earlier attempt at fixing this problem. The approach
suggested here is more robust.

--
Ticket URL: <https://code.djangoproject.com/ticket/21198#comment:5>

Django

unread,
Oct 13, 2013, 12:25:47 PM10/13/13
to django-...@googlegroups.com
#21198: @python_2_unicode_compatible, abstract models, working on 1.4 but causing
infinite loop on 1.5.
---------------------------+-------------------------------------
Reporter: jpic | Owner: aaugustin
Type: Bug | Status: closed
Component: Utilities | Version: 1.5
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------+-------------------------------------
Changes (by Aymeric Augustin <aymeric.augustin@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"f0c7649b1692f8441eb9b9b923b2bed8e95f9185"]:
{{{
#!CommitTicketReference repository=""
revision="f0c7649b1692f8441eb9b9b923b2bed8e95f9185"
Fixed #21198 -- Prevented invalid use of @python_2_unicode_compatible.

Thanks jpic for the report and chmodas for working on a patch.

Reverts 2ea80b94. Refs #19362.

Conflicts:
tests/utils_tests/test_encoding.py
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/21198#comment:6>

Django

unread,
Oct 13, 2013, 12:25:48 PM10/13/13
to django-...@googlegroups.com
#21198: @python_2_unicode_compatible, abstract models, working on 1.4 but causing
infinite loop on 1.5.
---------------------------+-------------------------------------
Reporter: jpic | Owner: aaugustin
Type: Bug | Status: closed
Component: Utilities | Version: 1.5
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------+-------------------------------------

Comment (by Aymeric Augustin <aymeric.augustin@…>):

In [changeset:"589dc49e129f63801c54c15e408c944a345b3dfe"]:
{{{
#!CommitTicketReference repository=""
revision="589dc49e129f63801c54c15e408c944a345b3dfe"


Fixed #21198 -- Prevented invalid use of @python_2_unicode_compatible.

Thanks jpic for the report and chmodas for working on a patch.

Reverts 2ea80b94. Refs #19362.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/21198#comment:7>

Reply all
Reply to author
Forward
0 new messages