jenkins-bot has submitted this change and it was merged.
Change subject: ItemPage.fromPage should strip #section ......................................................................
ItemPage.fromPage should strip #section
When ItemPage.fromPage is asked to create an ItemPage object from a Page, if the Page object has a 'section', it will send the #section urlencoded to Wikibase API to be resolved to a data item, and Wikibase will return -1 (missing).
Bug: 72317 Change-Id: Ifd6976f4132f827ddb12670dfe391ff7e7661d53 --- M pywikibot/page.py M tests/wikibase_tests.py 2 files changed, 15 insertions(+), 1 deletion(-)
Approvals: Multichill: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py index 1b2b788..2c3db36 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -3150,7 +3150,7 @@ # clear id, and temporarily store data needed to lazy loading the item del i.id i._site = page.site - i._title = page.title() + i._title = page.title(withSection=False) if not lazy_load and not i.exists(): raise pywikibot.NoPage(i) return i diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py index f41640e..4c6d932 100644 --- a/tests/wikibase_tests.py +++ b/tests/wikibase_tests.py @@ -280,6 +280,20 @@ item.get() self.assertTrue(item.exists())
+ def test_fromPage_noprops_with_section(self): + page = pywikibot.Page(self.nyc.site, self.nyc.title() + '#foo') + item = pywikibot.ItemPage.fromPage(page) + self.assertEqual(item._link._title, '-1') + self.assertTrue(hasattr(item, 'id')) + self.assertTrue(hasattr(item, '_content')) + self.assertEqual(item.title(), 'Q60') + self.assertTrue(hasattr(item, '_content')) + self.assertEqual(item.id, 'Q60') + self.assertEqual(item.getID(), 'Q60') + self.assertEqual(item.getID(numeric=True), 60) + item.get() + self.assertTrue(item.exists()) + def test_fromPage_props(self): page = self.nyc # fetch page properties
pywikibot-commits@lists.wikimedia.org