﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
35388	`force_debug_cursor` does nothing in async	James Ostrander	nobody	"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.
"	Bug	new	Database layer (models, ORM)	5.0	Normal		connection, db, orm, force_debug_cursor	James Ostrander	Unreviewed	0	0	0	0	0	0
