Re: [Django] #34174: async process_exception being called as sync from async view/middleware

2022-11-23 Thread Django
#34174: async process_exception being called as sync from async view/middleware
-+-
 Reporter:  Gabriel Rado |Owner:  Gabriel
 Type:   |  Rado
  Cleanup/optimization   |   Status:  closed
Component:  Documentation|  Version:  4.1
 Severity:  Normal   |   Resolution:  invalid
 Keywords:  middleware async | Triage Stage:  Accepted
  process_exception  |
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by Carlton Gibson):

 OK, thanks for the follow-up. Do reopen if you're able to reduce it to an
 issue in Django.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070184a4d917ed-5b2c885b-c24d-4bf0-b9a4-b8dc7cac75d3-00%40eu-central-1.amazonses.com.


Re: [Django] #34174: async process_exception being called as sync from async view/middleware

2022-11-23 Thread Django
#34174: async process_exception being called as sync from async view/middleware
-+-
 Reporter:  Gabriel Rado |Owner:  Gabriel
 Type:   |  Rado
  Cleanup/optimization   |   Status:  closed
Component:  Documentation|  Version:  4.1
 Severity:  Normal   |   Resolution:  invalid
 Keywords:  middleware async | Triage Stage:  Accepted
  process_exception  |
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Gabriel Rado):

 * status:  assigned => closed
 * resolution:   => invalid


Comment:

 i tried to create a test to demonstrate this behavior and every try was
 successfull. thinking the problem could be another point of my project and
 not django itself, i'll close this ticket

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070184a4d17551-cc2d89f7-4b8c-4824-8f41-578bc9a9df01-00%40eu-central-1.amazonses.com.


Re: [Django] #34174: async process_exception being called as sync from async view/middleware

2022-11-22 Thread Django
#34174: async process_exception being called as sync from async view/middleware
-+-
 Reporter:  Gabriel Rado |Owner:  Gabriel
 Type:   |  Rado
  Cleanup/optimization   |   Status:  assigned
Component:  Documentation|  Version:  4.1
 Severity:  Normal   |   Resolution:
 Keywords:  middleware async | Triage Stage:  Accepted
  process_exception  |
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Gabriel Rado):

 * owner:  nobody => Gabriel Rado
 * status:  new => assigned


-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070184a08253b2-acb2fd64-aa0b-4b63-829d-0f34356360b6-00%40eu-central-1.amazonses.com.


Re: [Django] #34174: async process_exception being called as sync from async view/middleware

2022-11-21 Thread Django
#34174: async process_exception being called as sync from async view/middleware
-+-
 Reporter:  Gabriel Rado |Owner:  nobody
 Type:   |   Status:  new
  Cleanup/optimization   |
Component:  Documentation|  Version:  4.1
 Severity:  Normal   |   Resolution:
 Keywords:  middleware async | Triage Stage:  Accepted
  process_exception  |
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Carlton Gibson):

 * stage:  Unreviewed => Accepted


Comment:

 Hi Gabriel. OK, seems right, are you happy to suggest a docs adjustment?
 (… but if you could add a test to demonstrate what you're seeing
 explicitly, that would be good too.) Thanks.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/010701849e35c37c-e2d3c23a-2dcc-4e56-80b6-a810ec5e92a3-00%40eu-central-1.amazonses.com.


Re: [Django] #34174: async process_exception being called as sync from async view/middleware

2022-11-21 Thread Django
#34174: async process_exception being called as sync from async view/middleware
-+-
 Reporter:  Gabriel Rado |Owner:  nobody
 Type:   |   Status:  new
  Cleanup/optimization   |
Component:  Documentation|  Version:  4.1
 Severity:  Normal   |   Resolution:
 Keywords:  middleware async | Triage Stage:
  process_exception  |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Description changed by Gabriel Rado:

Old description:

> following this bold part of the
> docs[https://docs.djangoproject.com/en/4.1/topics/http/middleware
> /#asynchronous-support]:
>

> process_view, process_template_response and process_exception methods, if
> they are provided, **should also be adapted to match the sync/async
> mode**. However, Django will individually adapt them as required if you
> do not, at an additional performance penalty.
>
> I' using this middleware to parse errors from sync and async views:
>

> {{{
> @sync_and_async_middleware
> def custom_error(get_response):
> if asyncio.iscoroutinefunction(get_response):
>
> async def middleware(request):
> response = await get_response(request)
> return response
>
> async def _process_exception(request, exception):
> return my_custom_process_exception(exception)
>
> else:
>
> def middleware(request):
> response = get_response(request)
> return response
>
> def _process_exception(request, exception):
> return my_custom_process_exception(exception)
>
> middleware.process_exception = _process_exception
> return middleware
> }}}
>
> and I'm getting "ValueError: The view my_view.view_func didn't return an
> HttpResponse object. It returned an unawaited coroutine instead. You may
> need to add an 'await' into your view." from
> here[https://github.com/django/django/blob/main/django/core/handlers/base.py#L257]
>
> i thought that with an async middleware + async view, all my hooks
> (process_view, process_template_response and process_exception) should be
> also async, but it appears that is mandatory to use sync
> process_exception with async capable middlewares. if this is intended,
> could the official docs be changed to expose this mandatory behavior?

New description:

 following this bold part from
 [https://docs.djangoproject.com/en/4.1/topics/http/middleware
 /#asynchronous-support]:
 > process_view, process_template_response and process_exception methods,
 if they are provided, **should also be adapted to match the sync/async
 mode**. However, Django will individually adapt them as required if you do
 not, at an additional performance penalty.

 I'm using this middleware to parse errors from sync and async views:


 {{{
 @sync_and_async_middleware
 def custom_error(get_response):
 if asyncio.iscoroutinefunction(get_response):

 async def middleware(request):
 response = await get_response(request)
 return response

 async def _process_exception(request, exception):
 return my_custom_process_exception(exception)

 else:

 def middleware(request):
 response = get_response(request)
 return response

 def _process_exception(request, exception):
 return my_custom_process_exception(exception)

 middleware.process_exception = _process_exception
 return middleware
 }}}

 and I'm getting "ValueError: The view my_view.view_func didn't return an
 HttpResponse object. It returned an unawaited coroutine instead. You may
 need to add an 'await' into your view." from
 [https://github.com/django/django/blob/main/django/core/handlers/base.py#L257]

 i thought that with an async middleware + async view, all my hooks
 (process_view, process_template_response and process_exception) should be
 also async, but it appears that is mandatory to use sync process_exception
 with async capable middlewares. if this is intended, could the official
 docs be changed to expose this mandatory behavior?

--

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 

[Django] #34174: async process_exception being called as sync from async view/middleware

2022-11-21 Thread Django
#34174: async process_exception being called as sync from async view/middleware
-+-
   Reporter:  Gabriel|  Owner:  nobody
  Rado   |
   Type: | Status:  new
  Cleanup/optimization   |
  Component: |Version:  4.1
  Documentation  |   Keywords:  middleware async
   Severity:  Normal |  process_exception
   Triage Stage: |  Has patch:  0
  Unreviewed |
Needs documentation:  0  |Needs tests:  0
Patch needs improvement:  0  |  Easy pickings:  0
  UI/UX:  0  |
-+-
 following this bold part of the
 docs[https://docs.djangoproject.com/en/4.1/topics/http/middleware
 /#asynchronous-support]:


 process_view, process_template_response and process_exception methods, if
 they are provided, **should also be adapted to match the sync/async
 mode**. However, Django will individually adapt them as required if you do
 not, at an additional performance penalty.

 I' using this middleware to parse errors from sync and async views:


 {{{
 @sync_and_async_middleware
 def custom_error(get_response):
 if asyncio.iscoroutinefunction(get_response):

 async def middleware(request):
 response = await get_response(request)
 return response

 async def _process_exception(request, exception):
 return my_custom_process_exception(exception)

 else:

 def middleware(request):
 response = get_response(request)
 return response

 def _process_exception(request, exception):
 return my_custom_process_exception(exception)

 middleware.process_exception = _process_exception
 return middleware
 }}}

 and I'm getting "ValueError: The view my_view.view_func didn't return an
 HttpResponse object. It returned an unawaited coroutine instead. You may
 need to add an 'await' into your view." from
 
here[https://github.com/django/django/blob/main/django/core/handlers/base.py#L257]

 i thought that with an async middleware + async view, all my hooks
 (process_view, process_template_response and process_exception) should be
 also async, but it appears that is mandatory to use sync process_exception
 with async capable middlewares. if this is intended, could the official
 docs be changed to expose this mandatory behavior?

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/010701849a90f7e4-e68d4713-a0b0-4631-8d23-9cb4a19a8fa4-00%40eu-central-1.amazonses.com.