Page MenuHomePhabricator

Undefined behavior and invalid index in pywikibot.date.formats['MonthName']
Closed, ResolvedPublicBUG REPORT

Description

Steps to Reproduce:

In a Python shell in the Pywikibot root directory (i.e. $ python3), issue the following commands:

>>> from pywikibot import date
>>> date.formats['MonthName']['hu']('január')
>>> date.formats['MonthName']['hu']('május')

Close the shell, open it again, and try again. Repeat it a few times.

Actual Results:

  • The first one (január) returns a random number [1..12] (stable within one shell run, but otherwise unpredictable).
  • The second one raises ValueError: 'május' is not in list.

Expected Results:

  • The first one consistently returns 1.
  • The second one consistently returns 5.

Notes:

  • Both bugs were introduced in 54f223acc1ec by @Xqt.
  • First bug: site.mediawiki_messages() returns a dictionary, and it looks like list(dict) is not stable in Python.
  • Second bug: it queries MediaWiki:may, but that’s the abbreviation (similar to MediaWiki:jan); it should use MediaWiki:may_long instead. Both the abbreviation and the full name are May in English, but in Hungarian the former is máj, while the latter is május.

(Yes, these are two separate bugs, but as they were introduced together, easier to reproduce together, and probably also faster to fix together, I decided to open one ticket for them. Feel free to make it two if you disagree.)

Event Timeline

Xqt triaged this task as High priority.Feb 2 2021, 6:05 AM

looks like list(dict) is not stable in Python.

What is your Python version?

Change 661016 had a related patch set uploaded (by Xqt; owner: Xqt):
[pywikibot/core@master] [bugfix] Fix date.formats['MonthName'] behaviour

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

looks like list(dict) is not stable in Python.

What is your Python version?

I have 3.5.3 on my local machine (latest version available on Debian 9). However, this bug was surfaced first on Toolforge by atobot’s szubcsonk task—I don’t know what Python version Toolforge bots have, but probably you do.

looks like list(dict) is not stable in Python.

What is your Python version?

I have 3.5.3 on my local machine (latest version available on Debian 9). However, this bug was surfaced first on Toolforge by atobot’s szubcsonk task—I don’t know what Python version Toolforge bots have, but probably you do.

If I understand T268438 right, it is 3.5 - unfortunately.

Change 661016 merged by jenkins-bot:
[pywikibot/core@master] [bugfix] Fix date.formats['MonthName'] behaviour

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