#35388: `force_debug_cursor` does nothing in async
-------------------------------------+-------------------------------------
     Reporter:  James Ostrander      |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  4.2
  (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 James Ostrander:

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.
>

> **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.

New description:

 Django version: 4.2.11
 Python version: 3.12

 Settings:

 {{{
 DEBUG=False
 LOGGING = {
     "version": 1,
     "disable_existing_loggers": False,
     "handlers": {
         "default": {
             "level": "DEBUG",
             "class": "logging.StreamHandler",
         },
     },
     "loggers": {
         "django.db.backends": {
             "handlers": ["default"],
             "level": "DEBUG",
             "propagate": 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: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/0107018ef21871b1-2eff41c3-0c3f-49f6-83f4-cf87e359f559-000000%40eu-central-1.amazonses.com.

Reply via email to