Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#24133 closed Bug (fixed)

DeleteView success_url bug for non ascii urls

Reported by: Laurent Payot Owned by: nobody
Component: Generic views Version: 1.7
Severity: Normal Keywords: DeleteView
Cc: 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 Laurent Payot)

When using DeleteView mixin with success_url = reverse_lazy('www:media-list') for a non-ASCII "delete URL" (e.g. /fr/médias/2139079220/Jules-Verne-cinq-semaines-en-ballon/suppression/ ) I get the following error :

Internal Server Error: /fr/médias/2139079220/Jules-Verne-cinq-semaines-en-ballon/suppression/
Traceback (most recent call last):
  File "/opt/VENV/publiberty/lib/python3.4/site-packages/django/core/handlers/", line 111, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/opt/VENV/publiberty/lib/python3.4/site-packages/django/views/generic/", line 69, in view
    return self.dispatch(request, *args, **kwargs)
  File "/opt/VENV/publiberty/lib/python3.4/site-packages/django/utils/", line 29, in _wrapper
    return bound_func(*args, **kwargs)
  File "/opt/VENV/publiberty/lib/python3.4/site-packages/django/contrib/auth/", line 22, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "/opt/VENV/publiberty/lib/python3.4/site-packages/django/utils/", line 25, in bound_func
    return func.__get__(self, type(self))(*args2, **kwargs2)
  File "/opt/VENV/publiberty/publiberty/django/www/", line 485, in dispatch
    return super().dispatch(*args, **kwargs)
  File "/opt/VENV/publiberty/lib/python3.4/site-packages/django/views/generic/", line 87, in dispatch
    return handler(request, *args, **kwargs)
  File "/opt/VENV/publiberty/lib/python3.4/site-packages/django/views/generic/", line 259, in post
    return self.delete(request, *args, **kwargs)
  File "/opt/VENV/publiberty/lib/python3.4/site-packages/django/views/generic/", line 253, in delete
    success_url = self.get_success_url()
  File "/opt/VENV/publiberty/lib/python3.4/site-packages/django/views/generic/", line 263, in get_success_url
    return self.success_url % self.object.__dict__
  File "/opt/VENV/publiberty/lib/python3.4/site-packages/django/utils/", line 179, in __mod__
    return six.text_type(self) % rhs
ValueError: unsupported format character 'C' (0x43) at index 6

For "normal" ASCII urls everything works fine.
Following workaround is working:

    def get_success_url(self):
        return reverse('www:media-list')

Could it be linked to the "accidental" fix of ticket 22693 ? I'm using Python 3.4.2 with Ubuntu 14.10.

Change History (10)

comment:1 Changed 8 years ago by Laurent Payot

Description: modified (diff)

comment:2 Changed 8 years ago by Laurent Payot

Description: modified (diff)

comment:3 Changed 8 years ago by Claude Paroz

Component: InternationalizationGeneric views
Has patch: unset
Triage Stage: UnreviewedAccepted

I think that using the old percent-based interpolation method in get_success_url was not very wise, considering that % is a common escape marker in URLs. I'd suggest using the new format interpolation method to elude conflicts with escaping percent characters in URLs.

comment:5 Changed 8 years ago by Claude Paroz

Keywords: reverse_lazy removed
Summary: DeleteView success_url = reverse_lazy(...) bug for non ascii urlsDeleteView success_url bug for non ascii urls

I think that reverse_lazy has nothing to do with the problem, hence removing from the summary.

comment:6 Changed 8 years ago by Tim Graham

Needs documentation: set

comment:7 Changed 8 years ago by Claude Paroz

Needs documentation: unset

comment:8 Changed 8 years ago by Tim Graham

Triage Stage: AcceptedReady for checkin

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

Resolution: fixed
Status: newclosed

In f48e2258a96a08dcec843921206bcf7656e3ae45:

Fixed #24133 -- Replaced formatting syntax in success_url placeholders

Thanks Laurent Payot for the report, and Markus Holtermann, Tim Graham
for the reviews.

comment:10 Changed 8 years ago by Tim Graham <timograham@…>

In 6eed9ae7:

Refs #24133 -- Removed legacy formatting syntax in success_url placeholders.

Per deprecation timeline.

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