Changes between Initial Version and Version 1 of Ticket #33772, comment 5


Ignore:
Timestamp:
Jun 8, 2022, 11:19:20 PM (2 years ago)
Author:
Simon Charette

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #33772, comment 5

    initial v1  
    33The crux of the issue remain; you are asking for an element at a particular index of a collection with an undefined ordering. Adding `order_by("example_model")` to your test case addresses the irregularity you are experiencing with `first()`.
    44
    5 `first()` could arguably be adjusted to raise an exception when attempted to be used on an unordered collection to ''refuse the temptation to guess'' but that would require a deprecation period. Another approach could be to only raise an exception when `first()` is called on a unordered queryset with an explicit `values()` that doesn't include `pk` which is the case reported here.
     5`first()` could arguably be adjusted to raise an exception when attempted to be used on an unordered collection to ''refuse the temptation to guess'' but that would require a deprecation period. Another approach could be to only raise an exception when `first()` is called on a unordered queryset with an explicit `values()` aggregation grouping that doesn't include `pk` which is the case reported here.
    66
    77Here's what the code could look like for a systematic error on attempts to use `first()` on a undefined ordering queryset performing aggregation over specific columns
Back to Top