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.

classification
Title: test_localtime_daylight_false_dst_true raises OverflowError: mktime argument out of range
Type: behavior Stage: needs patch
Components: email, Tests Versions: Python 3.4, Python 3.5
process
Status: closed Resolution: duplicate
Dependencies: Superseder: test_email: test_localtime_daylight_false_dst_true() fails depending on the timezone
View: 35317
Assigned To: Nosy List: BreamoreBoy, barry, belopolsky, lemburg, r.david.murray, trent, vstinner
Priority: normal Keywords:

Created on 2012-08-21 05:15 by trent, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (10)
msg168741 - (view) Author: Trent Nelson (trent) * (Python committer) Date: 2012-08-21 05:15
On the FreeBSD 8.2 build slave:

======================================================================
ERROR: test_localtime_daylight_false_dst_true (test_utils.LocaltimeTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/buildslave/python/3.x.snakebite-freebsd82-amd64/build/Lib/test/test_email/test_utils.py", line 86, in test_localtime_daylight_false_dst_true
    t1 = utils.localtime(t0, isdst=1)
  File "/home/buildslave/python/3.x.snakebite-freebsd82-amd64/build/Lib/email/utils.py", line 397, in localtime
    seconds = time.mktime(tm)
OverflowError: mktime argument out of range

======================================================================
ERROR: test_localtime_daylight_true_dst_true (test_utils.LocaltimeTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/buildslave/python/3.x.snakebite-freebsd82-amd64/build/Lib/test/test_email/test_utils.py", line 79, in test_localtime_daylight_true_dst_true
    t1 = utils.localtime(t0, isdst=1)
  File "/home/buildslave/python/3.x.snakebite-freebsd82-amd64/build/Lib/email/utils.py", line 397, in localtime
    seconds = time.mktime(tm)
OverflowError: mktime argument out of range

----------------------------------------------------------------------


Placeholder issue, haven't looked into it in detail yet.
msg168743 - (view) Author: Trent Nelson (trent) * (Python committer) Date: 2012-08-21 05:31
Narrowed it down to the following snippet:


>>> time.mktime((2012, 3, 12, 1, 1, 0, 0, 72, -1))
1331514060.0
[70780 refs]
>>> time.mktime((2012, 3, 12, 1, 1, 0, 0, 72, 1))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: mktime argument out of range
[70832 refs]


On all my FreeBSD boxes, that latter invocation always raises an OverflowError.
msg168747 - (view) Author: Trent Nelson (trent) * (Python committer) Date: 2012-08-21 06:47
All my servers are set to use UTC, which affects how FreeBSD (and other BSDs) treat the isdst param in struct tm in mktime:


#include <stdio.h>
#include <string.h>
#include <time.h>

int main(int argc, char **argv)
{
    struct tm tm1, tm2;
    time_t t1, t2;

    memset((void *)&tm1, 0, sizeof(struct tm));
    memset((void *)&tm2, 0, sizeof(struct tm));

    // UTC
    setenv("TZ", "UTC", 1);
    tzset();

    tm1.tm_sec = 0;
    tm1.tm_min = 1;
    tm1.tm_hour = 1;
    tm1.tm_mday = 12;
    tm1.tm_mon = 3;
    tm1.tm_year = 2012;
    tm1.tm_wday = -1;
    tm1.tm_yday = -1;
    tm1.tm_isdst = 1;

    t1 = mktime(&tm1);
    printf("t1 (UTC): %d\n", t1);

    // EST
    setenv("TZ", "CET", 1);
    tzset();
    tm2.tm_sec = 0;
    tm2.tm_min = 1;
    tm2.tm_hour = 1;
    tm2.tm_mday = 12;
    tm2.tm_mon = 3;
    tm2.tm_year = 2012;

    tm2.tm_wday = -1;
    tm2.tm_yday = -1;
    tm2.tm_isdst = 1;

    t2 = mktime(&tm2);
    printf("t2 (CET): %d\n", t2);

    return 0;
}


% gcc -g test_mktime.c -o test_time && ./test_time 
t1 (UTC): -1
t2 (CET): 1162787116

The two tests causing problems are Lib/test/test_email/test_utils.py:


    def test_localtime_daylight_false_dst_false(self):
        test.support.patch(self, time, 'daylight', False)
        t0 = datetime.datetime(2012, 3, 12, 1, 1)
        t1 = utils.localtime(t0, isdst=-1)
        t2 = utils.localtime(t1)
        self.assertEqual(t1, t2)

    def test_localtime_daylight_true_dst_true(self):
        test.support.patch(self, time, 'daylight', True)
        t0 = datetime.datetime(2012, 3, 12, 1, 1)
        t1 = utils.localtime(t0, isdst=1)
        t2 = utils.localtime(t1)
        self.assertEqual(t1, t2)


In order for those tests to work on a *BSD server with a TZ set to UTC, TZ is going to need to be set to something else first, and then tzset() called.  Otherwise, mktime() will return -1, which triggers the overflow error.
msg168755 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2012-08-21 11:40
email.utils.localtime() may reuse the new datetime.datetime.timestamp() method, except that this method doesn't support setting isdst (it is set to -1).
msg168760 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-08-21 12:10
This is 3.3 only, as those tests and the function they test were only introduced in 3.3.
msg168836 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-08-22 02:03
So you are saying that if the current timezone is UTC, FreeBSD's mktime just arbitrarily returns -1 for any time passed to it with the 'guess the DST flag' value set for is_dst?  And for is_dst set to 1 as well?  This isn't mentioned on the FreeBSD man page for mktime, as far as I can see.

If this is the real problem, we can fix it with the support.run_with_tz decorator, but...compiling and running your program on my linux box, I get -1 in both prints.
msg168839 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2012-08-22 02:13
> So you are saying that if the current timezone is UTC, FreeBSD's mktime
> just arbitrarily returns -1 for any time passed to it with the 'guess
> the DST flag' value set for is_dst?

I don't know about FreeBSD, but I recall seeing a comment in mxDT sources that some systems only allow isdst flag of -1 in mktime.

Adding Marc-Andre.
msg221856 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-06-29 16:04
Are these tests still failing, can this issue be closed as "out of date" or what?
msg221857 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-06-29 16:07
I don't see the issue anymore, I guess that it was fixed.
msg330442 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-11-26 15:49
I mark this issue as a duplicate of bpo-35317.
History
Date User Action Args
2022-04-11 14:57:35adminsetgithub: 59955
2018-11-26 15:49:11vstinnersetsuperseder: test_email: test_localtime_daylight_false_dst_true() fails depending on the timezone
resolution: fixed -> duplicate
messages: + msg330442
2014-06-29 16:07:03vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg221857
2014-06-29 16:04:19BreamoreBoysetnosy: + BreamoreBoy

messages: + msg221856
versions: + Python 3.4, Python 3.5, - Python 3.3
2012-08-22 02:13:03belopolskysetnosy: + lemburg
messages: + msg168839
2012-08-22 02:03:51r.david.murraysetmessages: + msg168836
2012-08-21 12:10:05r.david.murraysetversions: - Python 3.2
nosy: + barry, r.david.murray

messages: + msg168760

components: + email
2012-08-21 11:40:17vstinnersetmessages: + msg168755
2012-08-21 11:38:58vstinnersetnosy: + belopolsky, vstinner
2012-08-21 06:47:50trentsetmessages: + msg168747
2012-08-21 05:31:58trentsetmessages: + msg168743
2012-08-21 05:15:23trentcreate