Opened 6 years ago

Closed 19 months ago

Last modified 19 months 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 mtredinnick)

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

Attachments (1)

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

Download all attachments as: .zip

Change History (15)

Changed 6 years ago by liangent

comment:1 Changed 6 years ago by mtredinnick

  • Component changed from Internationalization to HTTP handling
  • Description modified (diff)
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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 6 years ago by mtredinnick

  • Version set to SVN

comment:3 Changed 6 years ago by liangent

( #10498 )

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

comment:4 Changed 4 years ago by SmileyChris

  • Severity set to Normal
  • Type set to Bug

comment:5 Changed 3 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:6 Changed 3 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:7 Changed 3 years ago by ramiro

  • Summary changed from an unevaluated lazy object to Passing a unicode-proxy to HttpResponse classes doesn't work

comment:8 Changed 2 years ago by ajeeshvt

  • Owner changed from nobody to ajeeshvt
  • Status changed from new to assigned

comment:9 Changed 2 years ago by anonymous

  • Status changed from assigned to new

comment:10 Changed 23 months ago by bmispelon

  • 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 20 months 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 20 months ago by claudep

  • Triage Stage changed from Accepted to Ready for checkin

comment:13 Changed 19 months ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from new to closed

In 3c45fb8589bfff580bb4d9d3c13172183c597abd:

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

Thanks liangent for the report.

comment:14 Changed 19 months 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