Files
app-store-optimization/skills/loki-mode/benchmarks/results/2026-01-05-01-24-17/swebench-patches/django__django-11133.patch

20 lines
1.3 KiB
Diff

Based on the issue description and hints provided, I can generate the patch. The issue is in the `make_bytes` method of `HttpResponseBase` class in `django/http/response.py`. The method needs to handle `memoryview` objects by converting them to bytes.
From the hints:
1. The `make_bytes` method should be adapted to handle memoryview objects by casting them to bytes
2. `force_bytes` already has memoryview support (added in commit d680a3f4477056c69629b0421db4bb254b8c69d0)
3. The fix is to add a check for memoryview and convert it to bytes
The typical structure of `make_bytes` checks for different types (string, bytes, etc.) and returns the appropriate bytes representation. Adding memoryview support would involve checking `isinstance(value, memoryview)` and returning `bytes(value)`.
--- a/django/http/response.py
+++ b/django/http/response.py
@@ -230,6 +230,9 @@ class HttpResponseBase:
def make_bytes(self, value):
"""Turn a value into a bytestring encoded in the output charset."""
+ # Handle memoryview
+ if isinstance(value, memoryview):
+ return bytes(value)
# Per PEP 3333, this response body must be bytes. To avoid returning
# an instance of a subclass, this function returns `bytes(googled)`. This
# doesn't make a copy when `value` already contains bytes.