jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/778675 )
Change subject: [bugfix]: Do not delete text when updating a Revision ......................................................................
[bugfix]: Do not delete text when updating a Revision
Do not overwrite existing Revision if it does not add text.
In tests: - reset cached revisions to keep test uniform for Page and ItemPage; Page and ItemPage have different side effects on page._revisions, due to BotMayEdit() implementations, and loadrevisions() does not necessarily reset Revision in cache.
Bug: T304786 Change-Id: I306291c50127594c6457e61e8d5b70daeead8557 --- M pywikibot/data/api.py M tests/basepage.py 2 files changed, 8 insertions(+), 2 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py index 4a89f13..f1b894b 100644 --- a/pywikibot/data/api.py +++ b/pywikibot/data/api.py @@ -3117,7 +3117,13 @@ def _update_revisions(page, revisions) -> None: """Update page revisions.""" for rev in revisions: - page._revisions[rev['revid']] = pywikibot.page.Revision(**rev) + revid = rev['revid'] + revision = pywikibot.page.Revision(**rev) + # do not overwrite an existing Revision if there is no content + if revid in page._revisions and revision.text is None: + pass + else: + page._revisions[revid] = revision
def _update_templates(page, templates) -> None: diff --git a/tests/basepage.py b/tests/basepage.py index 8a3fa70..fcd6bc8 100644 --- a/tests/basepage.py +++ b/tests/basepage.py @@ -53,6 +53,7 @@ custom_text = self.custom_text page.text = custom_text
+ page._revisions = {} self.site.loadrevisions(page, total=1)
self.assertTrue(hasattr(page, '_revid')) @@ -66,7 +67,6 @@
self.assertFalse(hasattr(page, '_text')) self.assertIsNone(page._revisions[page._revid].text) - self.assertFalse(hasattr(page, '_text')) self.assertIsNone(page._latest_cached_revision())
page.text = custom_text
pywikibot-commits@lists.wikimedia.org