Code

Opened 6 years ago

Closed 6 years ago

Last modified 3 years ago

#8287 closed (fixed)

Debug page shows wrong URL info when altering request.path

Reported by: kratorius Owned by: nobody
Component: HTTP handling Version: master
Severity: Keywords: request.path, urlconf, urls
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Not sure if this is a bug or an expected behavior, but anyway...
I have a middleware that alters request.path in order to hide a certain part of the URL to the views, so if I have an URL like /en/view/page/ this should become /view/page/. With recent upgrades this stopped working, and after a bit of investigating I found that this was due to [8015].
I spent a lot of time trying to understand why this was failing, since the debug page was showing the output I was expecting. For example, for /en/view/page I got:

Using the URLconf defined in project.urls, Django tried these URL patterns, in this order:

   ...
   3. ^view/(?P<title_slug>[\w-]+)/$
   ...

The current URL, view/page/, didn't match any of these.

While view/page/ matches the 3rd url pattern.
This happens because the debug page shows request.path, while the URLconf actually evaluates PATH_INFO and SCRIPT_NAME.
I fixed the problem by altering request.path_info as well, but shouldn't the debug page show the URL that is actually evaluated by URLconf?
In case this should be fixed I can provide a patch, but actually I don't know if .path_info should be always shown or must be shown only in certain places within the debug page.

Attachments (1)

wrong-url-r8338.patch (3.6 KB) - added by Giuliani Vito Ivan <giuliani.v@…> 6 years ago.
Shows right URL informations in debug page

Download all attachments as: .zip

Change History (8)

comment:1 Changed 6 years ago by mtredinnick

  • milestone set to 1.0
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

This is just an oversight when #245 was fixed. I didn't realise there was a change needed in the debug page.

Changed 6 years ago by Giuliani Vito Ivan <giuliani.v@…>

Shows right URL informations in debug page

comment:2 Changed 6 years ago by kratorius

  • Has patch set

comment:3 Changed 6 years ago by kratorius

The patch was written by me, just forgot to login.

comment:4 Changed 6 years ago by jcassee

Actually, I like the fact that the debugging page shows request.path instead of path_info. I too have been manipulating the request path (http://code.google.com/p/django-localeurl/, are we doing the same thing kratorius?) and I like the fact that the debug page shows the URL before the mangling sets in. On the other hand, path_info is probably what you want if you're debugging.

comment:5 Changed 6 years ago by kratorius

  • Summary changed from Debug page shows wrong URL info to Debug page shows wrong URL info when altering request.path

I thought the same thing, that's why I was asking if this was an intentional behaviour. But anyway if you're debugging (and this is the case, since we're talking about the debug page) the correct thing to do is to show the URL that is actually being evaluated rather then the actual, real, URL, otherwise there's the risk that you spend a lot of time trying to understand what's happening because the debug page doesn't give you any useful informations.

Anyway, we're doing more or less the same thing, except that your django-localeurl is much more complete than mine, and I'm going to replace my stuff with that :)

comment:6 Changed 6 years ago by jacob

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

(In [8633]) Fixed #8287: the debug page now shows the actual requested URL even if you've messed with request.path. Patch from Giuliani Vito Ivan.

comment:7 Changed 3 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

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.