Opened 14 minutes ago
#37505 new Bug
Django 6.1: TypeError in Query.add_select_col() when combining QuerySets with Meta.ordering referencing related model fields
| Reported by: | Ulrich Görtz | Owned by: | |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 6.1 |
| Severity: | Low | Keywords: | |
| Cc: | Ulrich Görtz | Triage Stage: | Unreviewed |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
The following problem occurs with Django 6.1, PostgreSQL, Python 3.14.
For a model (with a regular primary key) and Meta.ordering referencing fields through a foreign key (ordering = ('user__lastname', ), say), QuerySet.difference() applied to two QuerySets of that model (e.g., as a trivial example, A.objects.all().difference(A.objects.all())) throws a TypeError during SQL compilation because query.selected is None.
Adding .order_by() without arguments to the difference method resolves the problem.
The same query worked in Django 6.0. The problem might be related to #37466
Thanks for your work.