diff options
| author | Scott Halgrim <shalgrim@gmail.com> | 2022-11-08 12:19:59 +0100 |
|---|---|---|
| committer | Carlton Gibson <carlton@noumenal.es> | 2022-11-08 13:53:34 +0100 |
| commit | c4eaa67e2b880db778c9fe6d9854fbdfcc16ecd2 (patch) | |
| tree | a3d2aa24cd99ec75b204f8112caf04675c5a0f8f /django/test | |
| parent | 8e6ea1d153a852b83eaa4807301b143df1647a44 (diff) | |
Fixed #34063 -- Fixed reading request body with async request factory and client.
Co-authored-by: Kevan Swanberg <kevswanberg@gmail.com>
Co-authored-by: Carlton Gibson <carlton.gibson@noumenal.es>
Diffstat (limited to 'django/test')
| -rw-r--r-- | django/test/client.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/django/test/client.py b/django/test/client.py index 99e831aebd..8b926fc38d 100644 --- a/django/test/client.py +++ b/django/test/client.py @@ -14,7 +14,7 @@ from asgiref.sync import sync_to_async from django.conf import settings from django.core.handlers.asgi import ASGIRequest from django.core.handlers.base import BaseHandler -from django.core.handlers.wsgi import WSGIRequest +from django.core.handlers.wsgi import LimitedStream, WSGIRequest from django.core.serializers.json import DjangoJSONEncoder from django.core.signals import got_request_exception, request_finished, request_started from django.db import close_old_connections @@ -198,7 +198,8 @@ class AsyncClientHandler(BaseHandler): sender=self.__class__, scope=scope ) request_started.connect(close_old_connections) - request = ASGIRequest(scope, body_file) + # Wrap FakePayload body_file to allow large read() in test environment. + request = ASGIRequest(scope, LimitedStream(body_file, len(body_file))) # Sneaky little hack so that we can easily get round # CsrfViewMiddleware. This makes life easier, and is probably required # for backwards compatibility with external tests against admin views. @@ -598,7 +599,10 @@ class AsyncRequestFactory(RequestFactory): body_file = request.pop("_body_file") else: body_file = FakePayload("") - return ASGIRequest(self._base_scope(**request), body_file) + # Wrap FakePayload body_file to allow large read() in test environment. + return ASGIRequest( + self._base_scope(**request), LimitedStream(body_file, len(body_file)) + ) def generic( self, |
