Opened 15 years ago

Closed 11 years ago

Last modified 11 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: dev
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 15 years ago.

Download all attachments as: .zip

Change History (15)

by liangent, 15 years ago

Attachment: djtrans.zip added

comment:1 by Malcolm Tredinnick, 15 years ago

Component: InternationalizationHTTP handling
Description: modified (diff)
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 by Malcolm Tredinnick, 15 years ago

Version: SVN

comment:3 by liangent, 15 years ago

( #10498 )

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

comment:4 by Chris Beaven, 13 years ago

Severity: Normal
Type: Bug

comment:5 by Aymeric Augustin, 12 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:6 by Aymeric Augustin, 12 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:7 by Ramiro Morales, 12 years ago

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

comment:8 by ajeeshvt, 11 years ago

Owner: changed from nobody to ajeeshvt
Status: newassigned

comment:9 by anonymous, 11 years ago

Status: assignednew

comment:10 by Baptiste Mispelon, 11 years ago

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 by anonymous, 11 years ago

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 by Claude Paroz, 11 years ago

Triage Stage: AcceptedReady for checkin

comment:13 by Tim Graham <timograham@…>, 11 years ago

Resolution: fixed
Status: newclosed

In 3c45fb8589bfff580bb4d9d3c13172183c597abd:

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

Thanks liangent for the report.

comment:14 by Tim Graham <timograham@…>, 11 years ago

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