[Answer]-Inconsistent results from Django ORM

1๐Ÿ‘

I was able to solve the issue by changing the order_by('knz_updated_at) clause to order_by('knz_updated_at', 'id').

It seems that, in cases where both objects were updated in the same second, the ORM can be ambiguous about what value it returns (since Django DateTimeField only stores resolution to the second). Adding the id to the sort ensures that in cases of identical update times, the object created more recently will be returned.

๐Ÿ‘คkronosapiens

Leave a comment