Opened 8 years ago

Closed 3 years ago

Last modified 3 years ago

#10491 closed Bug (fixed)

Passing a unicode-proxy to HttpResponse classes doesn't work

Reported by: liangent Owned by: ajeeshvt
Component: HTTP handling Version: master
Severity: Normal Keywords:
Cc: liangent@…, bmispelon@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Malcolm Tredinnick)

Passing a ugettext_lazy() object as the argument to HttpResponseRedirect.__init__ doesn't work.

Attachments (1)

djtrans.zip (4.2 KB) - added by liangent 8 years ago.

Download all attachments as: .zip

Change History (15)

Changed 8 years ago by liangent

Attachment: djtrans.zip added

comment:1 Changed 8 years ago by Malcolm Tredinnick

Component: InternationalizationHTTP handling
Description: modified (diff)
Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Triage Stage: UnreviewedAccepted

Please report only on bug per ticket. This is two bugs:

  1. Passing a unicode-proxy to HttpResponse classes doesn't convert it to ASCII (it assumes a str or str-proxy objects will be passed in).
  2. Calling create() on a reverse ForeignKey causes problems.

I'm editing the description to describe the problem so that people don't have to work it out from the zip file and I'll open a new ticket for the second (entirely separate) problem. The original description was:

this shows <django.utils.functional.__proxy__ object at 0x0110ED10>, not xxx i expected

this bug also occurs when i'm trying to user.message_set.create(message=_(u'xxx'))

comment:2 Changed 8 years ago by Malcolm Tredinnick

Version: SVN

comment:3 Changed 8 years ago by liangent

( #10498 )

and i wonder where to modify description of a ticket (or just opened by myself)

comment:4 Changed 6 years ago by Chris Beaven

Severity: Normal
Type: Bug

comment:5 Changed 5 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:6 Changed 5 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:7 Changed 5 years ago by Ramiro Morales

Summary: an unevaluated lazy objectPassing a unicode-proxy to HttpResponse classes doesn't work

comment:8 Changed 4 years ago by ajeeshvt

Owner: changed from nobody to ajeeshvt
Status: newassigned

comment:9 Changed 4 years ago by anonymous

Status: assignednew

comment:10 Changed 3 years ago by Baptiste Mispelon

Cc: bmispelon@… added
Has patch: set

Looking into this, it turns out that HttpResponse accepts lazy objects without issue (I haven't checked, but I suspect the force_bytes call in HttpResponseBase.smart_bytes is what makes it work).

However, the problem is still there for HttpResponseRedirect.

I made a pull request that adds test for lazy object support in HttpResponse and HttpResponseRedirect and fix the behavior of HttpResponseRedirect (just adding a force_text call at the beginning of it).

https://github.com/django/django/pull/1022/files

comment:11 Changed 3 years ago by anonymous

I only hit upon this bug a couple of days ago. My use case was fairly common: automatic redirection to the login screen via the login_required decorator with LOGIN_URL setting being a lazily reversed url.

It used to work in Python 2.7 but fails in Python 3.3 inside urlparse() (that is assuming that HttpResponseRedirectBase has not changed lately).

Considering that Django allows lazy url-reverse for several versions now, I think fixing this is important.

comment:12 Changed 3 years ago by Claude Paroz

Triage Stage: AcceptedReady for checkin

comment:13 Changed 3 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: newclosed

In 3c45fb8589bfff580bb4d9d3c13172183c597abd:

Fixed #10491 -- Allowed passing lazy objects to HttpResponseRedirect.

Thanks liangent for the report.

comment:14 Changed 3 years ago by Tim Graham <timograham@…>

In badca4716fee99372ae545eaf6d5521db11348c1:

[1.6.x] Fixed #10491 -- Allowed passing lazy objects to HttpResponseRedirect.

Thanks liangent for the report.

Backport of 3c45fb8589 from master

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