Skip to content

Unsupported media type is not raised when posting a form #3214

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

Closed
wants to merge 1 commit into from

Conversation

canassa
Copy link
Contributor

@canassa canassa commented Aug 3, 2015

A HTTP status 415 "Unsupported media type" is not raised when a simple form (application/x-www-form-urlencoded) is posted to a view that accepts only application/json.

When posting other content-types, the 415 status is raised as expected.

The pull request includes a failing test.

@tomchristie
Copy link
Member

That's a bit of a glaring one - thanks for the test case pull request!

To consider - is this related to #1769?

@canassa
Copy link
Contributor Author

canassa commented Aug 4, 2015

I am not familiar with the DRF code, but I tried adding a breakpoint to the _parse method and I seems to not be called when the content-type is application/x-www-form-urlencoded. That's why the exception is not raised.

@tomchristie
Copy link
Member

Merged these tests into #3410, which resolves this. Thanks!

edmorley pushed a commit to mozilla/treeherder that referenced this pull request Nov 13, 2015
The default format used to make test requests is `multipart/form-data`,
unless overridden using `TEST_REQUEST_DEFAULT_FORMAT`:
http://www.django-rest-framework.org/api-guide/testing/#setting-the-default-format

Our API only accepts json and html (see `DEFAULT_RENDERER_CLASSES`), so
we should have always been setting `TEST_REQUEST_DEFAULT_FORMAT` to
`json`, to prevent test failures.

However until recently there was a bug preventing those failures:
encode/django-rest-framework#3214

Which has now been fixed in django-rest-framwork v3.3.x:
encode/django-rest-framework#3410

...so we must fix this before updating to the latest version of d-r-f.
edmorley pushed a commit to mozilla/treeherder that referenced this pull request Dec 6, 2015
The default format used to make test requests is `multipart/form-data`,
unless overridden using `TEST_REQUEST_DEFAULT_FORMAT`:
http://www.django-rest-framework.org/api-guide/testing/#setting-the-default-format

Our API only accepts json and html (see `DEFAULT_RENDERER_CLASSES`), so
we should have always been setting `TEST_REQUEST_DEFAULT_FORMAT` to
`json`, to prevent test failures.

However until recently there was a bug preventing those failures:
encode/django-rest-framework#3214

Which has now been fixed in django-rest-framwork v3.3.x:
encode/django-rest-framework#3410

...so we must fix this before updating to the latest version of d-r-f.
edmorley pushed a commit to mozilla/treeherder that referenced this pull request Dec 10, 2015
…pe json

The default format used to make test requests is `multipart/form-data`,
unless overridden using `TEST_REQUEST_DEFAULT_FORMAT`:
http://www.django-rest-framework.org/api-guide/testing/#setting-the-default-format

Our API only accepts json and html (see `DEFAULT_RENDERER_CLASSES`), so
we should have always been setting `TEST_REQUEST_DEFAULT_FORMAT` to
`json`, to prevent test failures.

However until recently there was a bug preventing those failures:
encode/django-rest-framework#3214

Which has now been fixed in django-rest-framwork v3.3.x:
encode/django-rest-framework#3410

...so we must fix this before updating to the latest version of d-r-f.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants