Opened 10 years ago

Closed 10 years ago

Last modified 9 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/base.py", 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/base.py", line 69, in view
    return self.dispatch(request, *args, **kwargs)
  File "/opt/VENV/publiberty/lib/python3.4/site-packages/django/utils/decorators.py", line 29, in _wrapper
    return bound_func(*args, **kwargs)
  File "/opt/VENV/publiberty/lib/python3.4/site-packages/django/contrib/auth/decorators.py", line 22, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "/opt/VENV/publiberty/lib/python3.4/site-packages/django/utils/decorators.py", line 25, in bound_func
    return func.__get__(self, type(self))(*args2, **kwargs2)
  File "/opt/VENV/publiberty/publiberty/django/www/views.py", line 485, in dispatch
    return super().dispatch(*args, **kwargs)
  File "/opt/VENV/publiberty/lib/python3.4/site-packages/django/views/generic/base.py", line 87, in dispatch
    return handler(request, *args, **kwargs)
  File "/opt/VENV/publiberty/lib/python3.4/site-packages/django/views/generic/edit.py", line 259, in post
    return self.delete(request, *args, **kwargs)
  File "/opt/VENV/publiberty/lib/python3.4/site-packages/django/views/generic/edit.py", line 253, in delete
    success_url = self.get_success_url()
  File "/opt/VENV/publiberty/lib/python3.4/site-packages/django/views/generic/edit.py", line 263, in get_success_url
    return self.success_url % self.object.__dict__
  File "/opt/VENV/publiberty/lib/python3.4/site-packages/django/utils/functional.py", 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 by Laurent Payot, 10 years ago

Description: modified (diff)

comment:2 by Laurent Payot, 10 years ago

Description: modified (diff)

comment:3 by Claude Paroz, 10 years ago

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

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 by Tim Graham, 10 years ago

Needs documentation: set

comment:7 by Claude Paroz, 10 years ago

Needs documentation: unset

comment:8 by Tim Graham, 10 years ago

Triage Stage: AcceptedReady for checkin

comment:9 by Claude Paroz <claude@…>, 10 years ago

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 by Tim Graham <timograham@…>, 9 years ago

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