order_by after select_related returns empty queryset
|Reported by:||ozgurisil@…||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||master|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
When querying a model with select_related(), if the related model contains a field which has null rows, adding the order_by() results in an empty set. However, count() gives the correct number of records.
Foo.objects.select_related('abc').order_by('x') # returns 
Foo.objects.select_related('abc').order_by('x').count() #returns correct number
If I fill the null rows with data, the problem vanishes.
This further leads to a "TemplateSyntaxError: 'NoneType' object has no attribute '_latest_transaction_cache'" in the template.
Change History (6)
comment:1 Changed 5 years ago by Alex
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Resolution set to worksforme
- Status changed from new to closed
comment:5 Changed 20 months ago by foxwhisper
- Easy pickings unset
- Resolution worksforme deleted
- Severity set to Normal
- Status changed from closed to new
- Type set to Uncategorized
- UI/UX unset