jenkins-bot merged this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[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/
M scripts/
M scripts/
3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/pywikibot/ b/pywikibot/
index c033a7d..736d34b 100644
--- a/pywikibot/
+++ b/pywikibot/
@@ -1428,7 +1428,7 @@'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)
raise pywikibot.NoPage(self)

diff --git a/scripts/ b/scripts/
index 64e3360..0d276af 100755
--- a/scripts/
+++ b/scripts/
@@ -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):
- except NoPage:
+ except (NoCreateError, NoPage):
pywikibot.error('Page {0} does not exist.'.format(
except LockedPage:
diff --git a/scripts/ b/scripts/
index b2a3cc5..5172505 100755
--- a/scripts/
+++ b/scripts/
@@ -45,7 +45,7 @@
"""Touch the given page."""
- except pywikibot.NoPage:
+ except (pywikibot.NoCreateError, pywikibot.NoPage):
pywikibot.error('Page {0} does not exist.'
except pywikibot.LockedPage:

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

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I6bd5d60d485cda0db2b10be80d92974758939961
Gerrit-Change-Number: 472374
Gerrit-PatchSet: 5
Gerrit-Owner: JJMC89 <>
Gerrit-Reviewer: D3r1ck01 <>
Gerrit-Reviewer: JJMC89 <>
Gerrit-Reviewer: Xqt <>
Gerrit-Reviewer: jenkins-bot (75)