Code

Opened 2 years ago

Last modified 2 weeks ago

#18494 new Bug

Positional arguments not passed to view functions in included urlconfs

Reported by: rfugger Owned by: nobody
Component: Core (URLs) Version: master
Severity: Normal Keywords: urls, urlconf
Cc: arv@…, stefantalpalaru, eduardocereto@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The docs say "An included URLconf receives any captured parameters from parent URLconfs":

https://docs.djangoproject.com/en/1.4/topics/http/urls/#captured-parameters

But this only works currently for named arguments, not positional ones. I've included a small project demonstrating the issue, with a runnable test case.

Attachments (3)

project.tar.gz (3.3 KB) - added by rfugger 2 years ago.
propagate_unnamed_groups_to_included_urlconfs.patch (980 bytes) - added by stefantalpalaru 2 years ago.
the fix
propagate_unnamed_groups_to_included_urlconfs2.patch (2.6 KB) - added by stefantalpalaru 2 years ago.
better fix and test case

Download all attachments as: .zip

Change History (10)

Changed 2 years ago by rfugger

Changed 2 years ago by stefantalpalaru

the fix

comment:1 Changed 2 years ago by stefantalpalaru

  • Cc stefantalpalaru added
  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

See the attached patch for a simple fix. I've tried to write a test for regressiontests but gave up in the process.

Changed 2 years ago by stefantalpalaru

better fix and test case

comment:2 Changed 2 years ago by stefantalpalaru

Better patch that only adds the unnamed matches from the parent pattern. I've also added a test.

comment:3 Changed 2 years ago by eduardocereto

  • Cc eduardocereto@… added

comment:4 Changed 2 years ago by SmileyChris

  • Resolution set to wontfix
  • Status changed from new to closed
  • Type changed from Bug to New feature

This is not a bug -- the docs specifically cover the current behaviour: https://docs.djangoproject.com/en/1.4/topics/http/urls/#the-matching-grouping-algorithm.

I can't see how we could introduce this without being backwards incompatible (someone may be using a mix and expecting the conf to ignore the unnamed groups).

comment:5 Changed 2 years ago by rfugger

  • Resolution wontfix deleted
  • Status changed from closed to reopened
  • Type changed from New feature to Bug

@SmileyChris, thanks for pointing that out. However, the documentation at that link states that positional arguments will be passed to view functions as long as there are no named arguments. My included project demonstrates that this is not working properly with included urlconfs. I have two suggestions:

  1. Have positional arguments passed to views as long as there are no named arguments, even when they were captured before included urlconfs, as per the matching-grouping algorithm documentation at your link.
  1. If this is too difficult to implement, update the documentation at:

https://docs.djangoproject.com/en/1.4/topics/http/urls/#captured-parameters

to say that positional arguments are never passed to views when they are captured before included urlconfs. Also update the matching-grouping algorithm documentation to say this.

Thanks!

comment:6 Changed 16 months ago by aaugustin

  • Status changed from reopened to new

comment:7 Changed 2 weeks ago by timo

  • Has patch unset

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as new
The owner will be changed from nobody to anonymous. Next status will be 'assigned'
as The resolution will be set. Next status will be 'closed'
Author


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

 
Note: See TracTickets for help on using tickets.