Skip to content

Admin changelist N+1 query causes Gunicorn worker timeout on /admin/sensors/sensorlocation/ #159

Description

@VinneyJ

Labels: bug, performance, admin
Linked Sentry: SENSORSAFRICA-API-13Z — https://code-for-africa.sentry.io/issues/7569887953/
Environment: production

/admin/sensors/sensorlocation/ triggers a per-row N+1 query pattern. A separate COUNT(*) FROM sensors_sensordatavalue plus a separate node lookup for each row in the changelist. With default list_per_page (~100), this fires 100+ sequential queries per page load, exceeding Gunicorn's worker timeout, which triggers a SIGABRT and SystemExit: 1.

Root cause

SensorLocationAdmin (or a related inline) lacks select_related/prefetch_related/annotate in get_queryset(). Likely a list_display callable or __str__ touching sensordata_set.count() per row.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions