#26626: Update decorator_from_middleware to work with new-style middleware
-------------------------------+------------------------------------
     Reporter:  Tim Graham     |                    Owner:  (none)
         Type:  New feature    |                   Status:  new
    Component:  HTTP handling  |                  Version:  dev
     Severity:  Normal         |               Resolution:
     Keywords:                 |             Triage Stage:  Accepted
    Has patch:  0              |      Needs documentation:  0
  Needs tests:  0              |  Patch needs improvement:  0
Easy pickings:  0              |                    UI/UX:  0
-------------------------------+------------------------------------
Comment (by Tanishq):

 Hi all,
 Just checking in—ticket #26626 appears to still be open, If it's still
 relevant for the dev branch, I've prepared a fix based on the use cases in
 comments 3–5.

 The patch updates
 {{{make_middleware_decorator}}} in {{{django/utils/decorators.py}}} to
 support new-style middleware by passing a proper
 {{{get_response}}} callable and invoking{{{__call__}}}. It refactors async
 handling to avoid event loop conflicts (using new loops for sync contexts
 and {{{await}}}in async ones), resolving un awaited coroutine warnings via
 proper exception handling, while maintaining compatibility with old-style
 middleware ({{{process_request}}}, {{{process_response}}}, etc.). Tests
 were added/updated in {{{tests/utils_tests/test_decorators.py}}}
 to cover sync/async{{{__call__}}}, {{{process_view}}},
 {{{process_exception}}},and {{{process_template_response}}}, all passing
 on Python 3.12. Verification was done using a reproduction script,
 reproduce_26626.py, which replicates the issue and confirms the fix.
 I’ll can submit a PR shortly with these changes and the reproduction
 script for review. Happy to address any feedback, including on whether to
 keep
 {{{reproduce_26626.py}}}!
-- 
Ticket URL: <https://code.djangoproject.com/ticket/26626#comment:8>
Django <https://code.djangoproject.com/>
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 [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/01070199332f5a61-eb42bce9-c4f5-4052-a7e8-eebf5a9d8499-000000%40eu-central-1.amazonses.com.

Reply via email to