jenkins-bot has submitted this change and it was merged.

Change subject: PageLoadInconsistentTitle exception for inconsistent 
page-loading results
......................................................................


PageLoadInconsistentTitle exception for inconsistent page-loading results

Errors for inconsistent page-loading results have been standardized.

Previously the same situation may have caused
"AttributeError: 'Page' object has no attribute '_pageid'"
which was harder to decipher. See T94826.

The new message does not include the method name itself; see
the stack trace instead.

Change-Id: I554417d81718158effe9bd3b1d233aa91a3464ef
---
M pywikibot/exceptions.py
M pywikibot/site.py
2 files changed, 37 insertions(+), 20 deletions(-)

Approvals:
  Xqt: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/pywikibot/exceptions.py b/pywikibot/exceptions.py
index a59b69b..2f5adb5 100644
--- a/pywikibot/exceptions.py
+++ b/pywikibot/exceptions.py
@@ -32,6 +32,9 @@
   - NotEmailableError: The target user has disabled email
   - NoMoveTarget: An expected move target page does not exist
 
+PageLoadRelatedError: any exception which happens while loading a Page.
+  - InconsistentTitleReceived: Page receives a title inconsistent with query
+
 PageSaveRelatedError: page exceptions within the save operation on a Page
 (alias: PageNotSaved).
 
@@ -231,6 +234,30 @@
     pass
 
 
+class PageLoadRelatedError(PageRelatedError):
+
+    """Loading the contents of a Page object has failed."""
+
+    message = u"Page %s was not loaded."
+
+
+class InconsistentTitleReceived(PageLoadRelatedError):
+
+    """Page receives a title inconsistent with query."""
+
+    def __init__(self, page, actual):
+        """Constructor.
+
+        @param page: Page that caused the exception
+        @type page: Page object
+        @param actual: title obtained by query
+        @type reason: basestring
+
+        """
+        self.message = "Query on %s returned data on '{0}'".format(actual)
+        super(InconsistentTitleReceived, self).__init__(page)
+
+
 class SiteDefinitionError(Error):  # noqa
 
     """Site does not exist"""
diff --git a/pywikibot/site.py b/pywikibot/site.py
index ce7f628..abbeb92 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -47,6 +47,7 @@
     IsNotRedirectPage,
     CircularRedirect,
     InterwikiRedirectPage,
+    InconsistentTitleReceived,
     LockedPage,
     CascadeLockedPage,
     LockedNoPage,
@@ -2862,14 +2863,11 @@
         except api.APIError:  # May occur if you are not logged in (no API 
read permissions).
             return (0, 0, 0)
 
-    def _update_page(self, page, query, method_name):
+    def _update_page(self, page, query):
         for pageitem in query:
             if not self.sametitle(pageitem['title'],
                                   page.title(withSection=False)):
-                pywikibot.warning(
-                    u"{0}: Query on {1} returned data on '{2}'".format(
-                        method_name, page, pageitem['title']))
-                continue
+                raise InconsistentTitleReceived(page, pageitem['title'])
             api.update_page(page, pageitem, query.props)
 
     def loadpageinfo(self, page, preload=False):
@@ -2883,7 +2881,7 @@
                                 type_arg="info",
                                 titles=title.encode(self.encoding()),
                                 inprop=inprop)
-        self._update_page(page, query, 'loadpageinfo')
+        self._update_page(page, query)
 
     def loadcoordinfo(self, page):
         """Load [[mw:Extension:GeoData]] info."""
@@ -2895,7 +2893,7 @@
                                         'country', 'region',
                                         'globe'],
                                 coprimary='all')
-        self._update_page(page, query, 'loadcoordinfo')
+        self._update_page(page, query)
 
     def loadpageprops(self, page):
         """Load page props for the given page."""
@@ -2904,7 +2902,7 @@
                                 type_arg="pageprops",
                                 titles=title.encode(self.encoding()),
                                 )
-        self._update_page(page, query, 'loadpageprops')
+        self._update_page(page, query)
 
     def loadimageinfo(self, page, history=False):
         """Load image info from api and save in page attributes.
@@ -2926,9 +2924,7 @@
         # self._update_page() pattern and remove return
         for pageitem in query:
             if not self.sametitle(pageitem['title'], title):
-                raise Error(
-                    u"loadimageinfo: Query on %s returned data on '%s'"
-                    % (page, pageitem['title']))
+                raise InconsistentTitleReceived(page, pageitem['title'])
             api.update_page(page, pageitem, query.props)
 
             if "imageinfo" not in pageitem:
@@ -3816,9 +3812,7 @@
         for pagedata in rvgen:
             if not self.sametitle(pagedata['title'],
                                   page.title(withSection=False)):
-                raise Error(
-                    u"loadrevisions: Query on %s returned data on '%s'"
-                    % (page, pagedata['title']))
+                raise InconsistentTitleReceived(page, pagedata['title'])
             if "missing" in pagedata:
                 raise NoPage(page)
             api.update_page(page, pagedata, rvgen.props)
@@ -3847,9 +3841,7 @@
                                   total=total)
         for pageitem in llquery:
             if not self.sametitle(pageitem['title'], lltitle):
-                raise Error(
-                    u"getlanglinks: Query on %s returned data on '%s'"
-                    % (page, pageitem['title']))
+                raise InconsistentTitleReceived(page, pageitem['title'])
             if 'langlinks' not in pageitem:
                 continue
             for linkdata in pageitem['langlinks']:
@@ -3870,9 +3862,7 @@
                                   total=total)
         for pageitem in elquery:
             if not self.sametitle(pageitem['title'], eltitle):
-                raise RuntimeError(
-                    "getlanglinks: Query on %s returned data on '%s'"
-                    % (page, pageitem['title']))
+                raise InconsistentTitleReceived(page, pageitem['title'])
             if 'extlinks' not in pageitem:
                 continue
             for linkdata in pageitem['extlinks']:

-- 
To view, visit https://gerrit.wikimedia.org/r/293957
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I554417d81718158effe9bd3b1d233aa91a3464ef
Gerrit-PatchSet: 7
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Whym <w...@whym.org>
Gerrit-Reviewer: John Vandenberg <jay...@gmail.com>
Gerrit-Reviewer: Mpaa <mpaa.w...@gmail.com>
Gerrit-Reviewer: MtDu <justin.d...@gmail.com>
Gerrit-Reviewer: Whym <w...@whym.org>
Gerrit-Reviewer: Xqt <i...@gno.de>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
Pywikibot-commits mailing list
Pywikibot-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to