#32049: Database connection differs between Middleware and views running under
ASGI.
-------------------------------------+-------------------------------------
     Reporter:  Hugo Osvaldo         |                    Owner:  nobody
  Barrera                            |
         Type:  Bug                  |                   Status:  closed
    Component:  HTTP handling        |                  Version:  3.1
     Severity:  Normal               |               Resolution:  invalid
     Keywords:  ASGI                 |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Description changed by Carlton Gibson:

Old description:

> All my views expect a particular middleware to have run (it detects the
> current tenant based on the request's host).
>
> I'm having an issue which ''only'' occurs on production, but I could not
> reproduce in development mode (even with `DEBUG=False`) nor via unit
> tests.
>
> After just inspecting stack traces, it seems that when `handler404` is
> run, behaviour varies between runserver and daphne.
>
> Looking at the backtrace of my `handler404` function:
>
> - When running `django-admin runserver 0.0.0.0:8000`, all my middlewares
> are in my backtrace, meaning they've gotten executed and the function is
> called in their context.
> - When running `daphne myapp.asgi:application --bind 0.0.0.0 --port 8000
> --http-timeout 90`, I put a tracepoint in my `handler404`, and the
> middleware **are not** in the backtrace. It seems that the view is run
> outside the context of these middlewares.
>
> I haven't been able to find anything in the docs clarifying whether error
> handlers should expect middleware to have run successfully, but whatever
> the ''intended'' behaviour is, it should be consistent across the two.

New description:

 (Was: Middleware behaviour inconsistent between runserver and daphne)

 All my views expect a particular middleware to have run (it detects the
 current tenant based on the request's host).

 I'm having an issue which ''only'' occurs on production, but I could not
 reproduce in development mode (even with `DEBUG=False`) nor via unit
 tests.

 After just inspecting stack traces, it seems that when `handler404` is
 run, behaviour varies between runserver and daphne.

 Looking at the backtrace of my `handler404` function:

 - When running `django-admin runserver 0.0.0.0:8000`, all my middlewares
 are in my backtrace, meaning they've gotten executed and the function is
 called in their context.
 - When running `daphne myapp.asgi:application --bind 0.0.0.0 --port 8000
 --http-timeout 90`, I put a tracepoint in my `handler404`, and the
 middleware **are not** in the backtrace. It seems that the view is run
 outside the context of these middlewares.

 I haven't been able to find anything in the docs clarifying whether error
 handlers should expect middleware to have run successfully, but whatever
 the ''intended'' behaviour is, it should be consistent across the two.

--

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32049#comment:4>
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 on the web visit 
https://groups.google.com/d/msgid/django-updates/068.8f21b8e1fe2d4321ec0808eb1f63a24b%40djangoproject.com.

Reply via email to