This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author izbyshev
Recipients benjamin.peterson, izbyshev, serhiy.storchaka, vstinner
Date 2018-11-05.22:53:29
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1541458409.73.0.788709270274.issue35171@psf.upfronthosting.co.za>
In-reply-to
Content
I've got the following on OpenSUSE Tumbleweed (glibc 2.27):

======================================================================
FAIL: test_TimeRE_recreation_timezone (test.test_strptime.CacheTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/scratch2/izbyshev/cpython/Lib/test/support/__init__.py", line 1683, in inner
    return func(*args, **kwds)
  File "/scratch2/izbyshev/cpython/Lib/test/test_strptime.py", line 702, in test_TimeRE_recreation_timezone
    self.assertEqual(tm.tm_isdst, 1)
AssertionError: 0 != 1

This test sets TZ environment variable to 'STD-1DST' and calls time.tzset() (inside support.run_with_tz decorator). This TZ value lacks rules that specify when DST transitions happen. POSIX seems to be silent what should be done if the rule is missing, thought it does specify that the rule is optional[1].

What actually happens at least on Linux/glibc[2] and FreeBSD[3] is that those rules are taken from 'posixrules' file. On OpenSUSE, it's linked to '/etc/localtime', which is linked to 'Europe/Moscow' in my case. DST transitions were cancelled in Russia in 2011, so when Python tries to get timezone names for two points of the year (https://github.com/python/cpython/blob/570e371fd6e8615ece9b9e21fbe77149ebeb172e/Modules/timemodule.c#L1603), it gets unexpected values instead. The actual values depend on the bugginess of the libc used:

* Glibc seems to be confused by having 'posixrules' file with DST cancelled but a specification which includes the DST timezone part, so localtime() returns 'MSK' in tm_zone (both for January and July).

* musl doesn't implement 'posixrules' fallback, so it uses "all-zero" rules instead which cause it return 'DST' in both cases.

* FreeBSD 11.1 (with 'posixrules' linked to 'Europe/Moscow') returns 'STD' in both cases.

With any of the above, the test fails because strptime is called with the same timezone name two times.

Note that even if PyInit_timezone() didn't probe January/July and used 'tzname' global instead, it wouldn't work as expected at least on FreeBSD: it sets tzname[1] to the empty string in the test above.

ISTM the best way to fix this is to remove dependence on 'posixrules' file by specifying the rules in TZ.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08
[2] http://man7.org/linux/man-pages/man3/tzset.3.html
[3] https://www.freebsd.org/cgi/man.cgi?query=tzset&sektion=3
History
Date User Action Args
2018-11-05 22:53:29izbyshevsetrecipients: + izbyshev, vstinner, benjamin.peterson, serhiy.storchaka
2018-11-05 22:53:29izbyshevsetmessageid: <1541458409.73.0.788709270274.issue35171@psf.upfronthosting.co.za>
2018-11-05 22:53:29izbyshevlinkissue35171 messages
2018-11-05 22:53:29izbyshevcreate