-
-
Notifications
You must be signed in to change notification settings - Fork 384
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
Put Doesn't Seem to Work Properly with Form Data #1059
Comments
This is a known issue. How to resolve?
from collections.abc import Callable
from typing import Any
from asgiref.sync import iscoroutinefunction, sync_to_async
from django.http import HttpRequest
from django.utils.decorators import sync_and_async_middleware
@sync_and_async_middleware
def process_put_patch(get_response: Callable) -> Callable:
async def async_middleware(request: HttpRequest) -> Any:
if (
request.method in ("PUT", "PATCH")
and request.content_type != "application/json"
):
initial_method = request.method
request.method = "POST"
request.META["REQUEST_METHOD"] = "POST"
await sync_to_async(request._load_post_and_files)()
request.META["REQUEST_METHOD"] = initial_method
request.method = initial_method
return await get_response(request)
def sync_middleware(request: HttpRequest) -> Any:
if (
request.method in ("PUT", "PATCH")
and request.content_type != "application/json"
):
initial_method = request.method
request.method = "POST"
request.META["REQUEST_METHOD"] = "POST"
request._load_post_and_files()
request.META["REQUEST_METHOD"] = initial_method
request.method = initial_method
return get_response(request)
return async_middleware if iscoroutinefunction(get_response) else sync_middleware
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
Versions:
I have a simple endpoint set up, that uses a a
ninja.File
, and accepts additional form data withninja.Form
:When trying to make this a PUT, I face the following error,
However, with everything the same, a POST works just fine with the data being properly validated as correct. I'm not sure if this is easily fixable, so feel free to close this out if it's not a priority. I saw this similar issue with Laravel, which it seems was never resolved: laravel/framework#13457
However, this might be a violation of this RFC: https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.6. It seems unclear to me whether the HTTP spec formally allows for this.
The text was updated successfully, but these errors were encountered: