Opened 3 weeks ago
Closed 3 weeks ago
#36773 closed Bug (needsinfo)
ManyToMany related manager .count() returns 0 while .all().count() returns correct value (Django 5.2.9 and 6.0.0)
| 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 (last modified by )
Environment
Django: 5.2.9
Python: 3.12.x
Database: PostgreSQL
OS: Ubuntu 22.04
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.
Change History (2)
comment:1 by , 3 weeks ago
| Description: | modified (diff) |
|---|
comment:2 by , 3 weeks ago
| Resolution: | → needsinfo |
|---|---|
| Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
Hello Daniel,
This could be a legitimate regression but without a proper set of models instructions to reproduce it's impossible for us to assess.
As you might have notice both c3a23aa02faa1cf1d32e43d66858e793cd9ecac4 and 66e47ac69a7e71cf32eee312d05668d8f1ba24bb include tests covering scenarios where the code behaves as expected so you might have run into particular scenario that isn't covered yet, or you might be using a third-party app that misbehaves, or something else might be at play here.
In other words, please help us help you, there is not much we can do with the little details you've provided so far.