Opened 3 years ago

Closed 3 years ago

#18860 closed Bug (invalid)

GET-parameters in `path` argument of `django.test.client.Client.get`

Reported by: lagunov.vladimir@… Owned by: nobody
Component: Testing framework Version: 1.4
Severity: Normal Keywords: Client
Cc: lvo@… Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Sometimes we need to send with Client query on URL that already contains GET parameters. In such situation method get of Client totally replaces parameters from URL and sends only parameters from argument data. This behavior isn't obvious and it would be more convenient for programmer if get will append parameters from data to query instead of replacing it.

Attachments (2)

client.diff (353 bytes) - added by anonymous 3 years ago.
client.2.diff (353 bytes) - added by lagunov.vladimir@… 3 years ago.

Download all attachments as: .zip

Change History (4)

Changed 3 years ago by anonymous

Changed 3 years ago by lagunov.vladimir@…

comment:1 Changed 3 years ago by claudep

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

The current behaviour is explicitely tested:

https://github.com/django/django/blob/master/tests/regressiontests/test_client_regress/tests.py#L822

It was introduced in:

https://github.com/django/django/commit/95d8c0619a

and documented:

https://docs.djangoproject.com/en/dev/topics/testing/#django.test.client.Client.get
("If you provide a URL with both an encoded GET data and a data argument, the data argument will take precedence.")

To me, your proposal makes sense. But I'd like to get the opinion of Russell (committer of changeset above) before moving on.

P.S. Please provide patches as unified diff format.

comment:2 Changed 3 years ago by russellm

  • Needs tests set
  • Resolution set to invalid
  • Status changed from new to closed

For context - there's a bit of history in play here. Once upon a time, you couldn't provide GET arguments in the query argument; you could only use the data argument. The test client was then modified to allow you to provide both a URL encoded query, and a data argument. This was done for two reasons:

1) Convenience in testing simple GET requests

2) Handling POSTs to URLs that contained query argument (e.g., POST "foo=whiz; pork=spam" to http://example.com/?foo=bar ).

The browser should always be the reference point here; So - What does a browser do if you submit a form using GET to http://example.com/?whiz=bang with a form payload of 'foo=whiz; pork=spam'? *That* is what the test client should do.

From my testing, if you use GET to submit a form with 'foo=whiz; pork=spam' to .?whiz=bang, the whiz=bang part is lost; you only get the foo and pork keys. This matches the existing behavior of the test client (allowing for the historical usage where GET arguments couldn't be passed in on the query itself).

So - I'm satisfied that the existing behavior is correct, and I'm marking the ticket invalid; however, if someone can make a case for another interpretation, feel free to reopen the ticket.

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