Use -id as a secondary key when retrieving latest page revision.

This fixes various unit tests on MySQL, where multiple revisions are committed in the space of one second, and the resolution of the created_at timestamp is insufficient to distinguish them.
pull/1020/head
Matt Westcott 2015-02-22 01:05:56 +00:00
rodzic 8dc8e9ca99
commit 4948b18e29
1 zmienionych plików z 2 dodań i 2 usunięć

Wyświetl plik

@ -481,7 +481,7 @@ class Page(six.with_metaclass(PageBase, MP_Node, ClusterableModel, index.Indexed
return revision
def get_latest_revision(self):
return self.revisions.order_by('-created_at').first()
return self.revisions.order_by('-created_at', '-id').first()
def get_latest_revision_as_page(self):
latest_revision = self.get_latest_revision()
@ -1097,7 +1097,7 @@ class PageRevision(models.Model):
# special case: a revision without an ID is presumed to be newly-created and is thus
# newer than any revision that might exist in the database
return True
latest_revision = PageRevision.objects.filter(page_id=self.page_id).order_by('-created_at').first()
latest_revision = PageRevision.objects.filter(page_id=self.page_id).order_by('-created_at', '-id').first()
return (latest_revision == self)
def publish(self):