Last modified: 2014-11-03 02:46:55 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T71664, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 69664 - WikibasePage.save fails without mwparserfromhell
WikibasePage.save fails without mwparserfromhell
Status: RESOLVED FIXED
Product: Pywikibot
Classification: Unclassified
Wikidata (Other open bugs)
core-(2.0)
All All
: Unprioritized normal
: ---
Assigned To: Fabian
:
: 70241 70978 (view as bug list)
Depends on:
Blocks: pwbpy3 py26
  Show dependency treegraph
 
Reported: 2014-08-17 13:44 UTC by John Mark Vandenberg
Modified: 2014-11-03 02:46 UTC (History)
1 user (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description John Mark Vandenberg 2014-08-17 13:44:37 UTC
Following on from bug 66120, we now get a TypeError during save (and other Page write methods).  The test added in the last changeset is identifying the issue:

ERROR: test_page_methods (__main__.TestPageMethods)
Test ItemPage methods inherited from superclass Page.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "tests/wikibase_tests.py", line 418, in test_page_methods
    self.assertRaises(pywikibot.PageNotSaved, self.wdp.save)
  File "/usr/local/lib/python2.6/site-packages/unittest2/case.py", line 475, in assertRaises
    callableObj(*args, **kwargs)
  File ".../pywikibot/__init__.py", line 476, in wrapper
    return method(*__args, **__kw)
  File ".../pywikibot/page.py", line 954, in save
    if not force and not self.botMayEdit():
  File ".../pywikibot/page.py", line 883, in botMayEdit
    templates = self.templatesWithParams()
  File ".../pywikibot/__init__.py", line 476, in wrapper
    return method(*__args, **__kw)
  File ".../pywikibot/page.py", line 1257, in templatesWithParams
    templates = textlib.extract_templates_and_params(self.text)
  File ".../pywikibot/textlib.py", line 923, in extract_templates_and_params
    return extract_templates_and_params_regex(text)
  File ".../pywikibot/textlib.py", line 943, in extract_templates_and_params_regex
    thistxt = removeDisabledParts(text)
  File ".../pywikibot/textlib.py", line 293, in removeDisabledParts
    return toRemoveR.sub('', text)
TypeError: expected string or buffer

That test hasnt caused an error for a while, but this test is against test.wikidata.org which has had a few other bugs needing fixing, and the server config appears to be changing frequently (getting better).

The error we see now is:

1. Page.save method calls botMayEdit
2. which calls templatesWithParams to look for {{nobots}}
3. which loads 'self.text' and
4. asks textlib.extract_templates_and_params() to extract all the templates

Page.text calls Page.get, which is supposed to return a string.

On a WikibasePage, .get returns a dict instead of a string.
Comment 1 Ricordisamoa 2014-09-02 00:54:48 UTC
*** Bug 70241 has been marked as a duplicate of this bug. ***
Comment 2 Fabian 2014-09-02 16:24:48 UTC
Currently I see there two “easy” fixes: One way to fix it would be in the second step to look either if text is a str/unicode.

The second would be to check if page is not a WikibasePage. But that one would break as soon as another Page subclass is introduced which also hasn't a text. Maybe it doesn't make sense that Wikibase is a subclass of Page, because the value stored internally are very different (but that now a bit late, because it's in the API now).

I'm not sure how redirects work actually. Would they return a string?
Comment 3 John Mark Vandenberg 2014-09-18 07:39:58 UTC
The same problem is happening on py3 win32
Comment 4 Fabian 2014-09-18 08:58:55 UTC
*** Bug 70978 has been marked as a duplicate of this bug. ***
Comment 5 Fabian 2014-09-18 09:01:10 UTC
When I
Comment 6 Fabian 2014-09-18 09:04:51 UTC
Okay that didn't go so well: What I meant to write was, that when mwparserfromhell is not installed it uses the regex which get's a dict in all versions of Python. I was able to reproduce the same error in Python 2.7.8.

But mwparserfromhell uses the string representation of the text so it quietly tries to interpret the dictionary, and as long as there is no 'template' code in any of the data it won't return any templates.

I might have a fix ready (at least in theory).
Comment 7 John Mark Vandenberg 2014-09-18 09:15:21 UTC
Duh, I should have figured out it was mwparserfromhell which was the commonality here.  I've re-added py3 compatibility, as installing mwparserfromhell on windows is not easy on py3, but has been solved on py2 with a packaged prebuilt dll.
Comment 8 Gerrit Notification Bot 2014-09-18 09:18:56 UTC
Change 161201 had a related patch set uploaded by XZise:
[FIX] WikibasePage: Allow saving wikibase pages without mwpfh

https://gerrit.wikimedia.org/r/161201
Comment 9 Gerrit Notification Bot 2014-09-18 09:47:47 UTC
Change 161201 merged by jenkins-bot:
[FIX] WikibasePage: Allow saving wikibase pages without mwpfh

https://gerrit.wikimedia.org/r/161201

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links