-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Allow empty data with content type application/json #1331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
"/", | ||
data=data, | ||
content_type="application/json", | ||
CONTENT_TYPE="application/json", # Force django test client to add the content-type even if no data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are both lines necessary? Or is it possible to remove one of the content_type parameters? (I didn't check what they do, do maybe it isn't a very smart question.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the second is to force the header option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes I see. The first makes Django automatically encode the data
as JSON, the second adds the header even if data
is falsy.
It's certainly convenient that Django automatically encodes the data if the content_type has some particular value. Sometimes the interdependence of different arguments just isn't obvious (enough) to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, unfortunately, this looks more like a trick, the django client don't add the content_type
if there is no data, so I add manually (extra kwargs which are not known by the test client are considered as extra headers).
Thanks, this looks very good! |
If you send content type = json but don't send JSON the system fails as well. Pseudo-code in django-debug-toolbar 3.1.1:
|
Oh right, that's a new case. Do you want submit a pull request @israel-tk ? Or maybe at least open an issue so that this problem isn't forgotten. |
Done creating a new issue: #1403 |
fix #1330