Code

Opened 17 months ago

Closed 17 months ago

Last modified 17 months ago

#19378 closed Bug (fixed)

HttpResponseRedirect fail on reverse_lazy with Python 3.2

Reported by: anonymous Owned by: nobody
Component: Generic views Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description


Attachments (1)

19378-1.diff (4.5 KB) - added by claudep 17 months ago.
Force reverse_lazy evaluation

Download all attachments as: .zip

Change History (6)

comment:1 Changed 17 months ago by Natim87

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Let's have an example :

In a delete view, you need to do that to fix the problem:

class TaskDeleteView(DeleteView):
    model = Task
    success_url = reverse_lazy('task:list')

    def get_success_url(self):
        return str(self.success_url)

If you don't define get_success_url and return the str() you get and attribute error proxy doesn't have a decode attribute.

comment:2 Changed 17 months ago by claudep

  • Component changed from Uncategorized to Generic views
  • Triage Stage changed from Unreviewed to Accepted

Mmmmh... it's not the first time I'm confronted with issues related to the new Python 3 urlparse implementation and its isinstance dance :-(

The problem cannot be triggered in ModelFormMixin-based views because the lazy reverse is resolved by an interpolation (self.success_url % self.object.__dict__). However, it is a problem in FormMixin version of get_success_url, where we probably will have to force the lazy evaluation.

Changed 17 months ago by claudep

Force reverse_lazy evaluation

comment:3 Changed 17 months ago by claudep

  • Has patch set

I was a bit surprised to not find existing FormView tests. Maybe I missed them?

comment:4 Changed 17 months ago by Claude Paroz <claude@…>

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

In 795ac7deda64e67a059b489f8684bb440ca7f7ad:

Fixed #19378 -- Ensured get_success_url returns a non-lazy URL

comment:5 Changed 17 months ago by Claude Paroz <claude@…>

In 7fea7cf5d74a488f0c81b76cb7dc7fa74a86569c:

[1.5.x] Fixed #19378 -- Ensured get_success_url returns a non-lazy URL

Backport of 795ac7deda from master.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.