[Django] #20017: format_html not working with lazy objects on jython

57 views
Skip to first unread message

Django

unread,
Mar 10, 2013, 6:51:51 AM3/10/13
to django-...@googlegroups.com
#20017: format_html not working with lazy objects on jython
-------------------------------+--------------------
Reporter: andreas@… | Owner: nobody
Type: Uncategorized | Status: new
Component: Python 2 | Version: 1.5
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
django.utils.html.format_html does not convert lazy string objects to
unicode on jython. E.g. the hidden csrf_token field looks like follows:

{{{
<input type="hidden" name="csrfmiddlewaretoken"
value="&lt;django.utils.functional.__proxy__ object at 0x1c7&gt;">
}}}

I attached a patch that fixes this bug.

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

Django

unread,
Mar 10, 2013, 6:54:49 AM3/10/13
to django-...@googlegroups.com
#20017: format_html not working with lazy objects on jython
---------------------------+--------------------------------------
Reporter: andreas@… | Owner: nobody
Type: Bug | Status: new

Component: Python 2 | Version: 1.5
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* needs_better_patch: => 0
* type: Uncategorized => Bug
* needs_tests: => 0
* needs_docs: => 0


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

Django

unread,
Mar 10, 2013, 10:22:59 AM3/10/13
to django-...@googlegroups.com
#20017: format_html not working with lazy objects on jython
---------------------------+--------------------------------------
Reporter: andreas@… | Owner: nobody
Type: Bug | Status: new

Component: Python 2 | Version: 1.5
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------+--------------------------------------
Changes (by apollo13):

* cc: apollo13 (added)


Comment:

Is that only an issue on jython or on python too?

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

Django

unread,
Mar 10, 2013, 11:29:03 AM3/10/13
to django-...@googlegroups.com
#20017: format_html not working with lazy objects on jython
---------------------------+--------------------------------------
Reporter: andreas@… | Owner: nobody
Type: Bug | Status: new

Component: Python 2 | Version: 1.5
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------+--------------------------------------

Comment (by andreas@…):

As far as I can see, it is only an issue on jython. I guess there is a
difference in the behaviour of the string.format method. However, '%s'
place holders are working fine with lazy string objects.

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

Django

unread,
Mar 10, 2013, 6:20:06 PM3/10/13
to django-...@googlegroups.com
#20017: format_html not working with lazy objects on jython
---------------------------+------------------------------------
Reporter: andreas@… | Owner: nobody
Type: Bug | Status: new

Component: Python 2 | Version: 1.5
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1

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

* needs_better_patch: 0 => 1
* needs_tests: 0 => 1
* stage: Unreviewed => Accepted


Comment:

We should review carefully what the expected type and what the actual type
are (str or unicode?), and make sure this is the correct level to fix the
problem. If we're indeed relying on an implicit cast, and that trips up
Jython, we should make it explicit. (str is unicode-based on Jython and
that could explain the problem.)

I would also like to see a test that fails on CPython; without such a test
we could easily reintroduce this problem in the future.

Minor comment on the patch: `args_safe` should use a list comprehension
rather than map/lambda.

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

Django

unread,
Mar 11, 2013, 10:19:52 AM3/11/13
to django-...@googlegroups.com
#20017: format_html not working with lazy objects on jython
---------------------------+------------------------------------
Reporter: andreas@… | Owner: nobody
Type: Bug | Status: new

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

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

Comment (by andreas@…):

I attached a new version of the patch that is using a list comprehension
instead of a map+lambda expression. Unfortunately I was not able to write
a test that reproduces the Jython behaviour on CPython.

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

Django

unread,
Mar 11, 2013, 10:32:11 AM3/11/13
to django-...@googlegroups.com
#20017: format_html not working with lazy objects on jython
---------------------------+------------------------------------
Reporter: andreas@… | Owner: nobody
Type: Bug | Status: new

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

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

Comment (by andreas@…):

I was able to fix the problem on a lower level, by assigning the {{{
__text_cast }}} method not only on the {{{ __unicode__ }}} method of the
Promise class, but also on the {{{ __str__ }}} method. But I am not sure
if that is the right thing to do.

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

Django

unread,
Apr 16, 2013, 12:54:33 PM4/16/13
to django-...@googlegroups.com
#20017: format_html not working with lazy objects on jython
---------------------------+------------------------------------
Reporter: andreas@… | Owner: nobody
Type: Bug | Status: new

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

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

Comment (by bmispelon):

This looks like it might be related to #20221.

Can you try applying the patch I made for it [1] and telling me if the
problem is still there?

Thanks.

[1] https://github.com/django/django/pull/1007

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

Django

unread,
Apr 16, 2013, 12:54:49 PM4/16/13
to django-...@googlegroups.com
#20017: format_html not working with lazy objects on jython
---------------------------+------------------------------------
Reporter: andreas@… | Owner: nobody
Type: Bug | Status: new

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

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

* cc: bmispelon@… (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/20017#comment:8>

Django

unread,
Apr 29, 2013, 5:16:37 AM4/29/13
to django-...@googlegroups.com
#20017: format_html not working with lazy objects on jython
---------------------------+------------------------------------
Reporter: andreas@… | Owner: nobody
Type: Bug | Status: new

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

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

Comment (by andreas@…):

Unfortunately your patch does not solve the problem with jython.

--
Ticket URL: <https://code.djangoproject.com/ticket/20017#comment:9>

Django

unread,
Dec 12, 2014, 7:35:38 PM12/12/14
to django-...@googlegroups.com
#20017: format_html not working with lazy objects on jython
---------------------------+-------------------------------------
Reporter: andreas@… | Owner: nobody
Type: Bug | Status: closed

Component: Python 2 | Version: 1.5
Severity: Normal | Resolution: needsinfo

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

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

* status: new => closed
* resolution: => needsinfo


Comment:

[https://pythonhosted.org/django-jython/ django-jython] has been updated
to work with Django 1.7. I'd think we would have heard about this issue if
it were still a problem. Please reopen with more details if it can still
be reproduced.

--
Ticket URL: <https://code.djangoproject.com/ticket/20017#comment:10>

Reply all
Reply to author
Forward
0 new messages