[Django] #29268: Support passing content_type=None to test.Client.post() to get the default value

19 views
Skip to first unread message

Django

unread,
Mar 28, 2018, 12:24:12 AM3/28/18
to django-...@googlegroups.com
#29268: Support passing content_type=None to test.Client.post() to get the default
value
---------------------------------------------+------------------------
Reporter: Chris Jerdonek | Owner: nobody
Type: New feature | Status: new
Component: Testing framework | Version: 2.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
---------------------------------------------+------------------------
Currently, passing `content_type=None` to
[https://github.com/django/django/blob/76ae1e9a94cbfddbbf115ad96f26901ba5c02d44/django/test/client.py#L532
`test.Client.post()`] results in the following error:

{{{
TypeError: expected string or bytes-like object
}}}

instead of causing the default `content_type` value. It would be more
user-friendly if passing `None` resulted in the default value.

One reason is as follows. Currently, if one wants to create a wrapper
function around `post()` with the same default behavior, the user either
needs to (1) duplicate / hard-code the default value in their wrapper
function, or (2) special-case `None` with a second invocation of `post()`
using a different function signature (i.e. one that doesn't pass //any//
`content_type` value). You can even see this happening in `client.py` with
the way that `Client.post()` invokes `RequestFactory.post()` -- the
default needs to be hard-coded twice.

--
Ticket URL: <https://code.djangoproject.com/ticket/29268>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 28, 2018, 10:18:44 AM3/28/18
to django-...@googlegroups.com
#29268: Support passing content_type=None to test.Client.post() to get the default
value
--------------------------------------+------------------------------------

Reporter: Chris Jerdonek | Owner: nobody
Type: Cleanup/optimization | Status: new

Component: Testing framework | Version: 2.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham):

* type: New feature => Cleanup/optimization
* stage: Unreviewed => Accepted


Comment:

Should the same design be used for the other HTTP methods that have
`content_type='application/octet-stream'`?

--
Ticket URL: <https://code.djangoproject.com/ticket/29268#comment:1>

Django

unread,
Mar 28, 2018, 1:00:17 PM3/28/18
to django-...@googlegroups.com
#29268: Support passing content_type=None to test.Client.post() to get the default
value
--------------------------------------+------------------------------------

Reporter: Chris Jerdonek | Owner: nobody
Type: Cleanup/optimization | Status: new

Component: Testing framework | Version: 2.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Chris Jerdonek):

Oh, good observation. I didn't examine the other methods. Yes, I do.

Generally, I've found this type of style / pattern helpful anywhere an API
has a default value. Perhaps other areas of Django could use a similar
treatment. Might it be a candidate for the
[https://docs.djangoproject.com/en/dev/internals/contributing/writing-code
/coding-style/ style guide]?

--
Ticket URL: <https://code.djangoproject.com/ticket/29268#comment:2>

Django

unread,
Mar 29, 2018, 4:55:26 AM3/29/18
to django-...@googlegroups.com
#29268: Support passing None to test Client and RequestFactory request methods for
default content_type
-------------------------------------+-------------------------------------
Reporter: Chris Jerdonek | Owner: Chris
Type: | Jerdonek
Cleanup/optimization | Status: assigned

Component: Testing framework | Version: 2.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Chris Jerdonek):

* owner: nobody => Chris Jerdonek
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/29268#comment:3>

Django

unread,
Mar 29, 2018, 7:15:06 AM3/29/18
to django-...@googlegroups.com
#29268: Support passing None to test Client and RequestFactory request methods for
default content_type
-------------------------------------+-------------------------------------
Reporter: Chris Jerdonek | Owner: Chris
Type: | Jerdonek
Cleanup/optimization | Status: assigned
Component: Testing framework | Version: 2.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Chris Jerdonek):

I started working on this here:
https://github.com/cjerdonek/django/tree/ticket_29268

--
Ticket URL: <https://code.djangoproject.com/ticket/29268#comment:4>

Django

unread,
Feb 12, 2021, 4:20:46 AM2/12/21
to django-...@googlegroups.com
#29268: Support passing None to test Client and RequestFactory request methods for
default content_type
--------------------------------------+------------------------------------
Reporter: Chris Jerdonek | Owner: (none)
Type: Cleanup/optimization | Status: new

Component: Testing framework | Version: 2.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Mariusz Felisiak):

* owner: Chris Jerdonek => (none)
* status: assigned => new


--
Ticket URL: <https://code.djangoproject.com/ticket/29268#comment:5>

Django

unread,
Feb 23, 2026, 2:00:58 PM (11 days ago) Feb 23
to django-...@googlegroups.com
#29268: Support passing None to test Client and RequestFactory request methods for
default content_type
-------------------------------------+-------------------------------------
Reporter: Chris Jerdonek | Owner: Anurag
Type: | Verma
Cleanup/optimization | Status: assigned
Component: Testing framework | Version: 2.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Anurag Verma):

* owner: (none) => Anurag Verma
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/29268#comment:6>

Django

unread,
Feb 24, 2026, 5:36:41 AM (11 days ago) Feb 24
to django-...@googlegroups.com
#29268: Support passing None to test Client and RequestFactory request methods for
default content_type
-------------------------------------+-------------------------------------
Reporter: Chris Jerdonek | Owner: Anurag
Type: | Verma
Cleanup/optimization | Status: assigned
Component: Testing framework | Version: 2.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Anurag Verma):

* has_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/29268#comment:7>
Reply all
Reply to author
Forward
0 new messages