Page MenuHomePhabricator

AttributeError: 'NoneType' object has no attribute 'calendarmodel' - we should raise more descriptive error when Wikibase is not available
Closed, ResolvedPublic

Description

date_value = pwb.WbTime(year=2016, month=11)

in a script gives error

pywikibot/__init__.py", line 499, in __init__
calendarmodel = site.calendarmodel()
AttributeError: 'NoneType' object has no attribute 'calendarmodel'

Running on

Pywikibot: [ssh] pywikibot-core.git (598599a, g7626, 2016/11/22, 12:43:36, n/a)
Release version: 3.0-dev
requests version: 2.11.1

Event Timeline

Magul added a subscriber: Magul.

Could You please provide information about You default site from user-config.py?

The only reason i can find for such error is that Your default page doesn't return wikibase information when asked for metadata or it return some information, but creation of data_repository is failing here.

Generally (assuming that You know Python) it fails because data_repository method is returning None (see: 1).

@Xqt, @jayvdb. @Mpaa, @Dalba, @valhallasw maybe we should raise some kind of error here (like NoSiteError or NoRepositoryError) instead of passing None and after that failing on AttributeError. That would make semantic sense here.

Which script are you running. What is the command line. Could you please file the whole traceback. A cannot reproduce this bug:

>>> import pwb, pywikibot as py
>>> WbT = py.WbTime(year=2016, month=11)
>>> WbT
WbTime(year=2016, month=11, day=1, hour=0, minute=0, second=0, precision=10, before=0, after=0, timezone=0, calendarmodel=http://www.wikidata.org/entity/Q1985727)
>>>

I am sorry, thank you for taking a look at it, it was my bad, I targeted a non-wikibase wiki with my user-config :(

I'm opening it, because I believe we should raise more descriptive error here.

Magul renamed this task from AttributeError: 'NoneType' object has no attribute 'calendarmodel' to AttributeError: 'NoneType' object has no attribute 'calendarmodel' - we should raise more descriptive error when Wikibase is not available.Nov 24 2016, 5:12 PM
Xqt triaged this task as Low priority.Nov 24 2016, 6:57 PM

Change 339946 had a related patch set uploaded (by Honeypot95):
__init__.py:Added extra checking for more descriptive error raising

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

Xqt claimed this task.

Change 339946 merged by Honeypot95:
[pywikibot/core] __init__.py:Added extra checking for more descriptive error raising

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

AttributeError means that there was an Error that had to do with an Attribute request. In general, when you write x.y, y is the purported attribute of x. NoneType means that instead of an instance of whatever Class or Object you think you're working with, you've actually got None. That usually means that an assignment or function call up failed or returned an unexpected result.

mylist = mylist.sort()

The sort() method of a list sorts the list in-place, that is, mylist is modified. But the actual return value of the method is None and not the list sorted. So you've just assigned None to mylist. If you next try to do, say, mylist.append(1) Python will give you this error.