jenkins-bot submitted this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[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(-)

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

To view, visit change 778675. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I306291c50127594c6457e61e8d5b70daeead8557
Gerrit-Change-Number: 778675
Gerrit-PatchSet: 9
Gerrit-Owner: Mpaa <mpaa.wiki@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged