Opened 10 years ago

Closed 9 years ago

#5982 closed (fixed)

Different behaviour for url parameter in dev run versus test run

Reported by: Manoj Govindan <egmanoj@…> Owned by: Leo Shklovskii
Component: Testing framework Version: master
Severity: Keywords:
Cc: egmanoj@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


URL configuration:

   url(r'^/find_thing/(?P<thing_name>.+)/$', '', name = 'find_thing'),


def find_thing(request, thing_name):
	print thing_name
	# perform look up of thing and return.

In the development environment ( runserver) the view works well when passed a string with a space in it, say 'my thing'.
The portion of the url representing the parameter shows up as 'my%20thing'.

I then wrote a test for the view using Django's test client. I used the utility reverse() method to pass the path to Client.get().
The test failed (the query set was empty) for identical input.

I added a print statement inside the view. On accessing the view in the development environment the parameter was printed as
'my thing'. However on running the test it was printed as 'my%20thing'. The latter caused the database lookup to return empty.

Why is the behaviour different in development/production and testing?

Attachments (2)

5982-r7023.diff (2.8 KB) - added by Russell Keith-Magee 9 years ago.
Test case for bug, against r7023
5982-r7264.diff (5.3 KB) - added by Leo Shklovskii 9 years ago.
modified test case and patch

Download all attachments as: .zip

Change History (10)

comment:1 Changed 10 years ago by Manoj Govindan <egmanoj@…>

Cc: egmanoj@… added

comment:2 Changed 9 years ago by Chris Beaven

Triage Stage: UnreviewedDesign decision needed

So it's probably a bug, I'm guessing the test client should be unquoting. Care to attach your test?

Changed 9 years ago by Russell Keith-Magee

Attachment: 5982-r7023.diff added

Test case for bug, against r7023

comment:3 Changed 9 years ago by Russell Keith-Magee

Triage Stage: Design decision neededAccepted

Bug appears to be real. I've added a test case; haven't had a chance to dig around for a fix.

comment:4 Changed 9 years ago by Leo Shklovskii

Owner: changed from nobody to Leo Shklovskii
Status: newassigned

Changed 9 years ago by Leo Shklovskii

Attachment: 5982-r7264.diff added

modified test case and patch

comment:5 Changed 9 years ago by Leo Shklovskii

Has patch: set
Triage Stage: AcceptedReady for checkin

Fixing this bug by adding urllib.unquote to the spot where PATH_INFO gets set in the test client. Based on
what I saw at django.core.servers.basehttp:565. That occurs for requests that come in via a normal client (on a dev server).

I've made a few minor changes to the test itself:

  • mixed space/tab indentation changed to all spaces
  • added cases to do a POST as well as a GET (since there are two separate code paths in the test client that set PATH_INFO)

Zero functional change cleanup changes in this patch:

  • removed unused imports from tests/regressiontests/test_client_regress/
  • added myself to the AUTHORS file

comment:6 Changed 9 years ago by Leo Shklovskii

Triage Stage: Ready for checkinAccepted

moving back to accepted (wasn't sure if I should have moved it)

comment:7 Changed 9 years ago by Jacob

Triage Stage: AcceptedReady for checkin

comment:8 Changed 9 years ago by Malcolm Tredinnick

Resolution: fixed
Status: assignedclosed

(In [7330]) Fixed #5982 -- Changed test client's URL processing to match core's (everything
gets run through urllib.unquote()). Patch from Leo Shklovskii and Russell

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