latest() does not behave as expected for equal timestamps
|Reported by:||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||master|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
When applying latest() to a field where two or more entries have equal timestamps, the entry with the lowest id is returned. What one would assume is that in such a case the entry with the highest id is returned.
Real life example: I run a ticket system that has the requirement of only storing the date (and not the time) where the status of the ticket changes. When a ticket is opened it is marked as "New". There is a page in my ticket system that shows the "New" tickets: i.e. the tickets that have "New" as the status returned by latest(). However, those tickets that are processed within the same day will still appear in this page. This is caused because all the status change entries for each of these tickets are in the same day and latest() will return the one with the lowest id.
I attach a one-line patch that fixes the issue.