jenkins-bot merged this change.

View Change

Approvals: JJMC89: Looks good to me, but someone else must approve Framawiki: Looks good to me, approved jenkins-bot: Verified
[bugfix] Solve wrong redirect status found for redirect filter in backlinks

- imageinfo property is always appended to the request parameter. If the
query result is only one page the imageinfo will cause a query continue and
the batch might not be completed if there are more than 1 file histories
but there are no other infos of the page like page info property. This
gives unexpected results as long as the imageinfo api generator result is
not handled properly.
- for a quick bugfix just increase "iilimit" to max and load all imageinfo
at once.
- Test for the related phab task added.

Bug: T194233
Change-Id: I6a38f1d57165b1fc3e089b11780669054e2c1788
---
M pywikibot/data/api.py
M tests/site_tests.py
2 files changed, 51 insertions(+), 0 deletions(-)

diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index d956df9..62bef1e 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -2921,6 +2921,7 @@
if not ('inprop' in parameters and 'protection' in parameters['inprop']):
appendParams(parameters, 'inprop', 'protection')
appendParams(parameters, 'iiprop', 'timestamp|user|comment|url|size|sha1|metadata')
+ appendParams(parameters, 'iilimit', 'max') # T194233
parameters['generator'] = generator
QueryGenerator.__init__(self, **kwargs)
self.resultkey = "pages" # element to look for in result
diff --git a/tests/site_tests.py b/tests/site_tests.py
index 62ff953..3a8be4b 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -2581,6 +2581,56 @@
for rev in mainpage._revisions.values()))


+class TestBacklinks(TestCase):
+
+ """Test for backlinks (issue T194233)."""
+
+ family = 'wikipedia'
+ code = 'en'
+
+ cached = True
+
+ def setUp(self):
+ """Setup tests."""
+ super(TestBacklinks, self).setUp()
+ self.page = pywikibot.Page(
+ self.site,
+ 'File:Băieţi de Cartier - La Familia cover.jpg')
+ self.backlinks = list(self.page.backlinks(followRedirects=False,
+ filterRedirects=True,
+ total=5))
+ self.references = list(self.page.getReferences(follow_redirects=True,
+ redirectsOnly=True,
+ total=5))
+ self.nofollow = list(self.page.getReferences(follow_redirects=False,
+ redirectsOnly=True,
+ total=5))
+
+ def test_backlinks_redirects_length(self):
+ """Test backlinks redirects lenght."""
+ self.assertEqual(len(self.backlinks), 1)
+ self.assertEqual(len(self.references), 1)
+ self.assertEqual(len(self.nofollow), 1)
+
+ def test_backlinks_redirects_status(self):
+ """Test backlinks redirects statur."""
+ for page in self.backlinks:
+ self.assertTrue(page.isRedirectPage())
+ for page in self.references:
+ self.assertTrue(page.isRedirectPage())
+ for page in self.nofollow:
+ self.assertTrue(page.isRedirectPage())
+
+ def test_backlinks_redirects_pageid(self):
+ """Test backlinks redirects pageid."""
+ for page in self.backlinks:
+ self.assertEqual(page.pageid, 45341783)
+ for page in self.references:
+ self.assertEqual(page.pageid, 45341783)
+ for page in self.nofollow:
+ self.assertEqual(page.pageid, 45341783)
+
+
class TestCommonsSite(TestCase):

"""Test cases for Site methods on Commons."""

To view, visit change 432767. To unsubscribe, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I6a38f1d57165b1fc3e089b11780669054e2c1788
Gerrit-Change-Number: 432767
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Framawiki <framawiki@tools.wmflabs.org>
Gerrit-Reviewer: JJMC89 <JJMC89.Wikimedia@gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444@gmail.com>
Gerrit-Reviewer: jenkins-bot <>