Opened 19 months ago
Last modified 19 months ago
#35388 closed New feature
`force_debug_cursor` does nothing in async — at Version 4
| Reported by: | James Ostrander | Owned by: | nobody |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 4.2 |
| Severity: | Normal | Keywords: | connection, db, orm, force_debug_cursor, async |
| Cc: | James Ostrander | Triage Stage: | Unreviewed |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
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.
Change History (4)
comment:1 by , 19 months ago
| Description: | modified (diff) |
|---|
comment:2 by , 19 months ago
| Version: | 5.0 → 4.2 |
|---|
comment:3 by , 19 months ago
comment:4 by , 19 months ago
| Description: | modified (diff) |
|---|
Note:
See TracTickets
for help on using tickets.
If the fix is something simple, I would be happy to submit a PR.