Opened 12 years ago
Closed 10 years ago
#20017 closed Bug (needsinfo)
format_html not working with lazy objects on jython
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Python 2 | Version: | 1.5 |
Severity: | Normal | Keywords: | |
Cc: | Florian Apolloner, bmispelon@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | yes | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
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="<django.utils.functional.__proxy__ object at 0x1c7>">
I attached a patch that fixes this bug.
Attachments (3)
Change History (13)
by , 12 years ago
Attachment: | jython_format_html_fix.diff added |
---|
comment:1 by , 12 years ago
Type: | Uncategorized → Bug |
---|
comment:2 by , 12 years ago
Cc: | added |
---|
comment:3 by , 12 years ago
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.
comment:4 by , 12 years ago
Needs tests: | set |
---|---|
Patch needs improvement: | set |
Triage Stage: | Unreviewed → Accepted |
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.
by , 12 years ago
Attachment: | jython_format_html_fix_v2.diff added |
---|
comment:5 by , 12 years ago
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.
by , 12 years ago
Attachment: | jython_lazy_fix.diff added |
---|
comment:6 by , 12 years ago
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.
comment:7 by , 12 years ago
comment:8 by , 12 years ago
Cc: | added |
---|
comment:10 by , 10 years ago
Resolution: | → needsinfo |
---|---|
Status: | new → closed |
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.
Is that only an issue on jython or on python too?