[Django] #35388: `force_debug_cursor` does nothing in async

12 views
Skip to first unread message

Django

unread,
Apr 18, 2024, 11:07:30 AM4/18/24
to django-...@googlegroups.com
#35388: `force_debug_cursor` does nothing in async
-------------------------------------+-------------------------------------
Reporter: jlost | Owner: nobody
Type: Bug | Status: new
Component: Database | Version: 5.0
layer (models, ORM) | Keywords: connection, db,
Severity: Normal | orm, force_debug_cursor
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/35388>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 18, 2024, 11:08:47 AM4/18/24
to django-...@googlegroups.com
#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:
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

unread,
Apr 18, 2024, 11:10:56 AM4/18/24
to django-...@googlegroups.com
#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
-------------------------------------+-------------------------------------
Changes (by James Ostrander):

* version: 5.0 => 4.2

--
Ticket URL: <https://code.djangoproject.com/ticket/35388#comment:2>

Django

unread,
Apr 18, 2024, 12:15:27 PM4/18/24
to django-...@googlegroups.com
#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
-------------------------------------+-------------------------------------
Comment (by James Ostrander):

If the fix is something simple, I would be happy to submit a PR.
--
Ticket URL: <https://code.djangoproject.com/ticket/35388#comment:3>

Django

unread,
Apr 18, 2024, 12:44:36 PM4/18/24
to django-...@googlegroups.com
#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,
},
},
--
Ticket URL: <https://code.djangoproject.com/ticket/35388#comment:4>
Reply all
Reply to author
Forward
0 new messages