jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/472374 )
Change subject: [FIX] Prevent touch from re-creating pages ......................................................................
[FIX] Prevent touch from re-creating pages
If a page no longer exists (deleted or moved without redirect) after being preloaded, Page.touch() would re-create the page with the text that was there when it was preloaded. Page.exists() will return True because the page existed at preloading.
Bug: T193833 Change-Id: I6bd5d60d485cda0db2b10be80d92974758939961 --- M pywikibot/page.py M scripts/newitem.py M scripts/touch.py 3 files changed, 5 insertions(+), 4 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py index c033a7d..736d34b 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -1428,7 +1428,7 @@ self.save(summary='Pywikibot touch edit', watch='nochange', minor=False, botflag=botflag, force=True, asynchronous=False, callback=callback, - apply_cosmetic_changes=False, **kwargs) + apply_cosmetic_changes=False, nocreate=True, **kwargs) else: raise pywikibot.NoPage(self)
diff --git a/scripts/newitem.py b/scripts/newitem.py index 64e3360..0d276af 100755 --- a/scripts/newitem.py +++ b/scripts/newitem.py @@ -30,7 +30,8 @@
import pywikibot from pywikibot import pagegenerators, WikidataBot -from pywikibot.exceptions import LockedPage, NoPage, PageNotSaved +from pywikibot.exceptions import (LockedPage, NoCreateError, NoPage, + PageNotSaved)
class NewItemRobot(WikidataBot): @@ -68,7 +69,7 @@ def _touch_page(page): try: page.touch() - except NoPage: + except (NoCreateError, NoPage): pywikibot.error('Page {0} does not exist.'.format( page.title(as_link=True))) except LockedPage: diff --git a/scripts/touch.py b/scripts/touch.py index b2a3cc5..5172505 100755 --- a/scripts/touch.py +++ b/scripts/touch.py @@ -45,7 +45,7 @@ """Touch the given page.""" try: page.touch(botflag=self.getOption('botflag')) - except pywikibot.NoPage: + except (pywikibot.NoCreateError, pywikibot.NoPage): pywikibot.error('Page {0} does not exist.' .format(page.title(as_link=True))) except pywikibot.LockedPage:
pywikibot-commits@lists.wikimedia.org