From 1fd9b44a6b1bde29fb1f6746e007787505608974 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Fri, 6 Nov 2020 12:34:50 +0100 Subject: [PATCH] Refs #32074 -- Fixed handling memoryview content by HttpResponse on Python 3.10+. An iterator was added to memoryview in Python 3.10, see https://bugs.python.org/issue41732 Refs #30294 --- django/http/response.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/django/http/response.py b/django/http/response.py index eedc03f118..91d4ddc880 100644 --- a/django/http/response.py +++ b/django/http/response.py @@ -351,7 +351,10 @@ class HttpResponse(HttpResponseBase): @content.setter def content(self, value): # Consume iterators upon assignment to allow repeated iteration. - if hasattr(value, '__iter__') and not isinstance(value, (bytes, str)): + if ( + hasattr(value, '__iter__') and + not isinstance(value, (bytes, memoryview, str)) + ): content = b''.join(self.make_bytes(chunk) for chunk in value) if hasattr(value, 'close'): try: