#35388: `force_debug_cursor` does nothing in async
-------------------------------------+-------------------------------------
     Reporter:  jlost                |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  5.0
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  connection, db,      |             Triage Stage:
  orm, force_debug_cursor            |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Description changed by jlost:

Old description:

> Django version: 4.2.11
> Python version: 3.12
>
> Settings:
>
> {{{
> DEBUG=False
> }}}
>
> For Pytest, where DEBUG=False, this removes a means of enabling query
> logging via override.
>

>
> {{{
> def query_test_sync(request: HttpRequest) -> HttpResponse:
>     from django.db import connection
>
>     connection.force_debug_cursor = True
>
>     a = Thing.objects.first()
>     return HttpResponse(f"First thing: {a.id}")
> }}}
>
> Log:
>
> {{{
> web-1       | [18/Apr/2024 14:48:35] "GET /test_query_sync/ HTTP/1.1" 200
> 31
> web-1       | (0.001) SELECT "thing_thing"."name", "thing_thing"."id"
> FROM "thing_thing" ORDER BY "thing_thing"."id" ASC LIMIT 1; args=();
> alias=default
> }}}
>

>

> {{{
> async def query_test_async(request: HttpRequest) -> HttpResponse:
>     from django.db import connection
>
>     connection.force_debug_cursor = True
>
>     a = await Thing.objects.afirst()
>     return HttpResponse(f"First thing: {a.id}")
> }}}
>
> Log:
>
> {{{
> web-1       | [18/Apr/2024 15:00:29] "GET /test_query_async/ HTTP/1.1"
> 200 31
> }}}
>

> Also worth noting: CaptureQueriesContext does not work in an async
> context.

New description:

 Django version: 4.2.11
 Python version: 3.12

 Settings:

 {{{
 DEBUG=False
 }}}

 For Pytest, where DEBUG=False, this removes a means of enabling query
 logging via override.


 **SYNC VIEW (WORKING):**
 {{{
 def query_test_sync(request: HttpRequest) -> HttpResponse:
     from django.db import connection

     connection.force_debug_cursor = True

     a = Thing.objects.first()
     return HttpResponse(f"First thing: {a.id}")
 }}}

 Log:

 {{{
 web-1       | [18/Apr/2024 14:48:35] "GET /test_query_sync/ HTTP/1.1" 200
 31
 web-1       | (0.001) SELECT "thing_thing"."name", "thing_thing"."id" FROM
 "thing_thing" ORDER BY "thing_thing"."id" ASC LIMIT 1; args=();
 alias=default
 }}}



 **ASYNC VIEW (NOT WORKING):**
 {{{
 async def query_test_async(request: HttpRequest) -> HttpResponse:
     from django.db import connection

     connection.force_debug_cursor = True

     a = await Thing.objects.afirst()
     return HttpResponse(f"First thing: {a.id}")
 }}}

 Log:

 {{{
 web-1       | [18/Apr/2024 15:00:29] "GET /test_query_async/ HTTP/1.1" 200
 31
 }}}


 Also worth noting: CaptureQueriesContext does not work in an async
 context.

--
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35388#comment:1>
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/0107018ef1c0b582-3162a507-8b4b-4470-89e0-1debecb85331-000000%40eu-central-1.amazonses.com.

Reply via email to