mirror of
https://github.com/django/django.git
synced 2024-11-21 19:09:18 +01:00
Refs #33735 -- Adjusted warning stacklevel in StreamingHttpResponse.__iter__()/__aiter__().
This commit is contained in:
parent
7e6e1c8383
commit
c042fe3a74
@ -498,6 +498,7 @@ class StreamingHttpResponse(HttpResponseBase):
|
||||
"StreamingHttpResponse must consume asynchronous iterators in order to "
|
||||
"serve them synchronously. Use a synchronous iterator instead.",
|
||||
Warning,
|
||||
stacklevel=2,
|
||||
)
|
||||
|
||||
# async iterator. Consume in async_to_sync and map back.
|
||||
@ -518,6 +519,7 @@ class StreamingHttpResponse(HttpResponseBase):
|
||||
"StreamingHttpResponse must consume synchronous iterators in order to "
|
||||
"serve them asynchronously. Use an asynchronous iterator instead.",
|
||||
Warning,
|
||||
stacklevel=2,
|
||||
)
|
||||
# sync iterator. Consume via sync_to_async and yield via async
|
||||
# generator.
|
||||
|
@ -258,8 +258,9 @@ class HandlerRequestTests(SimpleTestCase):
|
||||
"StreamingHttpResponse must consume asynchronous iterators in order to "
|
||||
"serve them synchronously. Use a synchronous iterator instead."
|
||||
)
|
||||
with self.assertWarnsMessage(Warning, msg):
|
||||
with self.assertWarnsMessage(Warning, msg) as ctx:
|
||||
self.assertEqual(b"".join(list(response)), b"streaming content")
|
||||
self.assertEqual(ctx.filename, __file__)
|
||||
|
||||
|
||||
class ScriptNameTests(SimpleTestCase):
|
||||
@ -350,10 +351,11 @@ class AsyncHandlerRequestTests(SimpleTestCase):
|
||||
"StreamingHttpResponse must consume synchronous iterators in order to "
|
||||
"serve them asynchronously. Use an asynchronous iterator instead."
|
||||
)
|
||||
with self.assertWarnsMessage(Warning, msg):
|
||||
with self.assertWarnsMessage(Warning, msg) as ctx:
|
||||
self.assertEqual(
|
||||
b"".join([chunk async for chunk in response]), b"streaming content"
|
||||
)
|
||||
self.assertEqual(ctx.filename, __file__)
|
||||
|
||||
async def test_async_streaming(self):
|
||||
response = await self.async_client.get("/async_streaming/")
|
||||
|
Loading…
Reference in New Issue
Block a user