Last modified: 2014-08-10 10:32:24 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 T68619, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 66619 - TypeError: list indices must be integers, not str
TypeError: list indices must be integers, not str
Status: RESOLVED FIXED
Product: Pywikibot
Classification: Unclassified
Wikidata (Other open bugs)
core-(2.0)
All All
: Normal normal
: ---
Assigned To: Pywikipedia bugs
u=dev c=backend p=0
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2014-06-14 17:19 UTC by Maarten Dammers
Modified: 2014-08-10 10:32 UTC (History)
6 users (show)

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


Attachments

Description Maarten Dammers 2014-06-14 17:19:44 UTC
File "C:\pywikibot\coredev\rijksmonumenten_import.py", line 106, in run
    result = self.repo.editEntity(identification, data, summary=summary)
  File "C:\pywikibot\coredev\pywikibot\site.py", line 566, in callee
    return fn(self, *args, **kwargs)
  File "C:\pywikibot\coredev\pywikibot\site.py", line 3750, in editEntity
    data = req.submit()
  File "C:\pywikibot\coredev\pywikibot\data\api.py", line 414, in submit
    message = result["error"]["messages"]["0"]["name"]
TypeError: list indices must be integers, not str
<type 'exceptions.TypeError'>
CRITICAL: Waiting for 1 network thread(s) to finish. Press ctrl-c to abort

We use ["0"] and that used to work. Maybe the upstream api was changed? This is a bit hard to reproduce.
Comment 1 Gerrit Notification Bot 2014-06-16 08:27:46 UTC
Change 139794 had a related patch set uploaded by Xqt:
(bug 66619) Ignore TypeError for bug 46535

https://gerrit.wikimedia.org/r/139794
Comment 2 xqt 2014-06-16 16:12:31 UTC
rijksmonumenten_import.py is not part of the framework. Could you give more information about values of editEntity(identification, data, summary=summary)?
Comment 3 xqt 2014-06-16 16:15:44 UTC
Or place a print statement in api.py line 412:

print result["error"] 

to get the whole error result
Comment 4 Maarten Dammers 2014-06-17 18:43:43 UTC
I haven't been able to reproduce this. Bot has been running for quite some time.

My assumption would be that the 'result["error"]["messages"]["0"]["name"]' causes the error because it's not four layers of dicts, but has a list in there somewhere. 

Anyone a clue how to trigger an error to see if the format of error messages might have changed?

The relevant snippet that triggered tis bug:

data = {'labels':
            {monument.get('lang'):
             {'language': monument.get('lang'),
              'value': monumentName}
             }
        }
identification = {}
summary = u'Creating new item with data from %s' % (monument.get('source'),)
pywikibot.output(summary)
result = self.repo.editEntity(identification, data, summary=summary)
Comment 5 Maarten Dammers 2014-06-18 19:05:46 UTC
Daniel probably broke it in https://gerrit.wikimedia.org/r/#/c/124323/

I asked him what to expect back in april, but never got a response http://lists.wikimedia.org/pipermail/wikidata-tech/2014-April/000473.html 

The Wikidata technical documentation is a mess so I can't find what to expect.

Wikidata people, could you please provide us, your downstream users, with some decent documentation on what to expect?
Comment 6 xqt 2014-06-27 15:13:26 UTC
Maarten, as you declined just to ignore the TypeError, I've uploaded a new path that should log the api request and its error content.
Comment 7 xqt 2014-07-05 17:41:54 UTC
See also bug 45277
Comment 8 Thiemo Mättig 2014-07-06 12:37:09 UTC
I don't know exactly what's happening here but it seems I have a very similar patch in review at https://gerrit.wikimedia.org/r/#/c/138660/

Please note that result["error"]["messages"] is not an array but an object (at least that's what I see in the JavaScript code my patch touches). I wonder why Python complains. Accessing the elements via ["0"] should work.
Comment 9 Maarten Dammers 2014-07-06 14:21:58 UTC
"0" is a string. If I would have a dict and a list:

somedict = { "0" : "bla", "1" : "more bla" }
somelist = ["bla", "more bla"]

I would access the "bla with somedict["0"] ("0" is a string here) and in the list I would do somelist[0] to access "bla.

>>> somedict = { "0" : "bla", "1" : "more bla" }
>>> somelist = ["bla", "more bla"]
>>> print somedict["0"]
bla
>>> print somelist["0"]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: list indices must be integers, not str
>>> print somelist[0]
bla
>>>

So if someone changed the output from a dict ("0") to list (0), that would explain this error.
Comment 10 xqt 2014-07-06 14:43:16 UTC
In past we had a structure like the following for the error:

{u'error': {u'code': u'failed-save',
            u'info': u'Another item (Q1151870) already has label "disambiguation" and description "Wikimedia disambiguation page" associated with language code en.',
            u'messages': {u'0': {u'name': u'wikibase-error-label-not-unique-item',
                                 u'parameters': [u'disambiguation',
                                                 u'en',
                                                 {},
                                                 u'Wikimedia disambiguation page'],
                                 u'type': u'error'},
                          u'html': {u'*': u'<p>Another item (Q1151870) already has label "disambiguation" and description "Wikimedia disambiguation page" associated with language code en.\n</p>'}}},
 u'servedby': u'mw1199'}


now result['error']['messages']['0']['name'] does not work anymore to get the u'wikibase-error-label-not-unique-item',
Comment 11 Thiemo Mättig 2014-07-06 19:28:07 UTC
Guys, you realize somebody needs to post an example API request that contains an error message and shows the wrong structure we are talking about? As I said, from what I know there is nothing wrong with the API. At the moment this looks like a coding error in Pywikibot to me. Which is nothing the Wikidata team can fix.
Comment 12 Maarten Dammers 2014-07-07 06:10:28 UTC
Yup, someone changed the output of the api, bot just crashed with this message:

{u'servedby': u'mw1129', u'error': {u'messages': [{u'html': {u'*': u'Could not create a new page.\nIt already exists.'}, u'name': u'edit-already-exists', u'parameters': []}]}}
Comment 13 Thiemo Mättig 2014-07-07 06:59:33 UTC
(In reply to Maarten Dammers from comment #12)
> bot just crashed with this message:

Again: Example URL?
Comment 14 John Mark Vandenberg 2014-07-07 08:37:22 UTC
(In reply to Maarten Dammers from comment #12)
> Yup, someone changed the output of the api, bot just crashed with this
> message:
> 
> {u'servedby': u'mw1129', u'error': {u'messages': [{u'html': {u'*': u'Could
> not create a new page.\nIt already exists.'}, u'name':
> u'edit-already-exists', u'parameters': []}]}}

Has anyone seen this bug except with 'edit-already-exists'?  It may be that one error is problematic, as it is a lower level part of the code which emits this error.
Comment 15 Maarten Dammers 2014-07-07 11:41:23 UTC
(In reply to Thiemo Mättig from comment #13)
> (In reply to Maarten Dammers from comment #12)
> > bot just crashed with this message:
> 
> Again: Example URL?

Not possible. All POST and intermittent.
Comment 16 xqt 2014-07-07 12:32:34 UTC
I uploaded a new PS to fix the API breaking change in Gerrit change #139794
Comment 17 Maarten Dammers 2014-07-07 15:51:04 UTC
I was thinking. Both cases might be mixed depending on what module is throwing the error. Maybe we should grab ['error']['messages'] and check if it's a list or a dict and depending on that, grab the message. 

That way we don't care any more about the format, we just accept both formats.
Comment 18 xqt 2014-07-07 16:09:27 UTC
Yes, have a look at my PS.
Comment 19 Thiemo Mättig 2014-07-07 16:51:58 UTC
Ok, I had a chance to talk to the rest of the Wikidata team. The fact that "messages" was not an array was a bug. It should be an array (with numeric keys, obviously).

The problem is that there are many different places where error messages are build. We started unifying them by introducing Wikibase ApiErrorReporter but this may not have cleaned up all instances. If you find situations where "messages" still is an object (with string keys) please report them.
Comment 20 Gerrit Notification Bot 2014-08-06 11:31:58 UTC
Change 152036 had a related patch set uploaded by XZise:
API change: error message is a list not a dict

https://gerrit.wikimedia.org/r/152036
Comment 21 Gerrit Notification Bot 2014-08-08 22:09:35 UTC
Change 139794 merged by jenkins-bot:
(bug 66619) API change: error message is a list not a dict

https://gerrit.wikimedia.org/r/139794
Comment 22 Gerrit Notification Bot 2014-08-10 10:32:24 UTC
Change 152036 abandoned by Xqt:
API change: error message is a list not a dict

Reason:
https://gerrit.wikimedia.org/r/#/c/139794/ is already merged.

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

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


Navigation
Links