Page MenuHomePhabricator

Date module does not have formats for wikidata
Closed, ResolvedPublic


When pywikibot is setup for Wikidata, and therefore the language code "wikidata" is chosen in the configuration (I set mine up with, attempting to use the date formatting from the date module fails.

Traceback (most recent call last):
  File "/path/to/core/pywikibot/", line 2104, in DayPageGenerator
    firstPage = pywikibot.Page(site, fd(startMonth, 1))
  File "/path/to/core/pywikibot/", line 2337, in __call__
    return formats['Day_' + enMonthNames[m-1]][](d)
KeyError: 'wikidata'

Event Timeline

Unicornisaurous raised the priority of this task from to Needs Triage.
Unicornisaurous updated the task description. (Show Details)
Unicornisaurous subscribed.

The final fix for this problem is probably going to depend on T71255 , which is a complex but low priority problem.

As an interim measure, you should be able use the following in your to bypass this problem

family = 'wikidata'
mylang = 'en'

That should let you continue to find other bugs in using the date module when used with Wikidata.

(Also, due to T85331 not being implemented, you'll need to test using the 'wikidata' family distributed as pywikibot/families/ , as it has hard-coded data needed to use wikidata)

Hmm, that isn't working for me. Now its failing differently:

Traceback (most recent call last):
  File "/path/to/core/tests/", line 455, in setUpClass
    super(CheckHostnameMixin, cls).setUpClass()
  File "/path/to/core/tests/", line 816, in setUpClass
  File "/path/to/core/pywikibot/", line 600, in Site
    _sites[key] = interface(code=code, fam=fam, user=user, sysop=sysop)
  File "/path/to/core/pywikibot/", line 1514, in __init__
    BaseSite.__init__(self, code, fam, user, sysop)
  File "/path/to/core/pywikibot/", line 518, in __init__
    % (self.__code,
UnknownSite: Language 'en' does not exist in family wikidata

Yeah that doesn't work for wikidata. It has two “languages”: “wikidata” and “test” so it won't automatically choose “wikidata” if the language doesn't match. This is actually T71255.

Grr. Sorry you're right.

So, to test, remove either the 'test' or 'wikidata' entry in self.langs of the official pywikibot/families/ , so only the one you are testing is in the dict

i.e. to test the production wikidata, use:

self.langs = {
    'wikidata': '',
    # 'test': '',

Then you can use family = 'wikidata' ; mylang = 'en'

Or to run test on the test wikidata site, use:

self.langs = {
    #  'wikidata': '',
     'test': '',

And then you can use family = 'wikidata' ; mylang = 'en'

As there are lots of unit tests that depend on both test and production wikidata, to test your new date pagegen tests without lots of errors from other tests, use the following syntax to invoke only your test methods:

$ python -m unittest tests.pagegeerators_tests.YourTestClass.test_your_test_method

(see tests/README.rst for more info)


I commented out one of the self.langs lines in the wikidata family file and my has

family = 'wikidata'
mylang = 'en'

...but now I'm back to the original error (same stacktrace)

KeyError: 'wikidata'

ok; interesting, and thanks for trying. So, for the moment, for your task skip the new date tests if the test site is Wikidata (it is a very special case, for other reasons).

Well AFAIK is the code always the code of the chosen site. Bit APISite has also a value lang which mustn't return the same value as APISite.code.

Change 182453 had a related patch set uploaded (by XZise):
[FIX] Data: Use site's language and not code


Change 182453 merged by jenkins-bot:
[FIX] Data: Use site's language and not code

Ricordisamoa assigned this task to XZise.
Ricordisamoa removed a project: Patch-For-Review.