Opened 4 years ago

Closed 4 years ago

Last modified 4 years 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 Claude Paroz 4 years ago.
Force reverse_lazy evaluation

Download all attachments as: .zip

Change History (6)

comment:1 Changed 4 years 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 4 years ago by Claude Paroz

Component: UncategorizedGeneric views
Triage Stage: UnreviewedAccepted

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

Attachment: 19378-1.diff added

Force reverse_lazy evaluation

comment:3 Changed 4 years ago by Claude Paroz

Has patch: set

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

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

Resolution: fixed
Status: newclosed

In 795ac7deda64e67a059b489f8684bb440ca7f7ad:

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

comment:5 Changed 4 years 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.

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