From e50160c83dd3311c65e1822c2e77c71c6e6f5111 Mon Sep 17 00:00:00 2001 From: Dave Brondsema Date: Thu, 2 Jan 2025 15:03:21 -0500 Subject: [PATCH] fix for wiki pages that don't have any history --- .../forgewiki/tests/functional/test_root.py | 16 ++++++++++++++++ ForgeWiki/forgewiki/wiki_main.py | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ForgeWiki/forgewiki/tests/functional/test_root.py b/ForgeWiki/forgewiki/tests/functional/test_root.py index 6459c853c..2d8aaef19 100644 --- a/ForgeWiki/forgewiki/tests/functional/test_root.py +++ b/ForgeWiki/forgewiki/tests/functional/test_root.py @@ -21,6 +21,8 @@ import json import PIL + +from forgewiki.model import Page from ming.odm.odmsession import ThreadLocalODMSession from mock import patch from tg import config @@ -262,6 +264,20 @@ def test_page_history(self): response.mustcontain('text1') response.mustcontain(no='text2') + def test_page_history_missing(self): + self.app.get(h.urlquote('/wiki/tést/')) + self.app.post( + h.urlquote('/wiki/tést/update'), + params={ + 'title': 'tést'.encode(), + 'text': 'text1', + 'labels': '', + }) + for snapshot in Page.query.get(title='tést').history(): + snapshot.delete() + r = self.app.get(h.urlquote('/wiki/tést/')) + r.mustcontain(no='There is a newer version') + def test_page_diff(self): self.app.post( h.urlquote('/wiki/tést/update'), diff --git a/ForgeWiki/forgewiki/wiki_main.py b/ForgeWiki/forgewiki/wiki_main.py index 1f66a7212..a24a1df4c 100644 --- a/ForgeWiki/forgewiki/wiki_main.py +++ b/ForgeWiki/forgewiki/wiki_main.py @@ -617,7 +617,7 @@ def index(self, version=None, page=0, limit=None, **kw): hide_left_bar = not (c.app.show_left_bar) subscribed_to_page = M.Mailbox.subscribed(artifact=self.page) latest_version = self.page.history().limit(1).first() - is_latest_version = cur == latest_version.version + is_latest_version = not latest_version or cur == latest_version.version return dict( page=page, cur=cur, prev=prev, next=next,