Opened 4 hours ago
Last modified 34 minutes ago
#36773 closed Bug
ManyToMany related manager .count() returns 0 while .all().count() returns correct value (Django 5.2.9 and 6.0.0) — at Initial Version
| Reported by: | Daniel Davtyan | Owned by: | |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 6.0 |
| Severity: | Release blocker | Keywords: | count, django, orm |
| Cc: | Daniel Davtyan | Triage Stage: | Unreviewed |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Environment
Django: 5.2.9
Python: 3.12.x
Database: PostgreSQL
OS: (e.g. Ubuntu 22.04 – fill in)
The same code previously worked correctly on Django 4.x. After upgrading to Django 5.x (now 6.0), I see a discrepancy between ManyToMany related manager .count() and .all().count() in tests.
This looks similar to the regression tracked as #36197, which was fixed for ManyToManyField related managers using a through model with to_field, but I am still seeing the same symptom on Django 5.2.9.