Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_localtime_daylight_false_dst_true raises OverflowError: mktime argument out of range #59955

Closed
tpn opened this issue Aug 21, 2012 · 10 comments
Labels
tests Tests in the Lib/test dir topic-email type-bug An unexpected behavior, bug, or error

Comments

@tpn
Copy link
Member

tpn commented Aug 21, 2012

BPO 15750
Nosy @malemburg, @warsaw, @abalkin, @vstinner, @tpn, @bitdancer
Superseder
  • bpo-35317: test_email: test_localtime_daylight_false_dst_true() fails depending on the timezone
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2014-06-29.16:07:03.876>
    created_at = <Date 2012-08-21.05:15:23.151>
    labels = ['type-bug', 'tests', 'expert-email']
    title = 'test_localtime_daylight_false_dst_true raises OverflowError: mktime argument out of range'
    updated_at = <Date 2018-11-26.15:49:11.334>
    user = 'https://github.com/tpn'

    bugs.python.org fields:

    activity = <Date 2018-11-26.15:49:11.334>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2014-06-29.16:07:03.876>
    closer = 'vstinner'
    components = ['Tests', 'email']
    creation = <Date 2012-08-21.05:15:23.151>
    creator = 'trent'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 15750
    keywords = []
    message_count = 10.0
    messages = ['168741', '168743', '168747', '168755', '168760', '168836', '168839', '221856', '221857', '330442']
    nosy_count = 7.0
    nosy_names = ['lemburg', 'barry', 'belopolsky', 'vstinner', 'trent', 'r.david.murray', 'BreamoreBoy']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'needs patch'
    status = 'closed'
    superseder = '35317'
    type = 'behavior'
    url = 'https://bugs.python.org/issue15750'
    versions = ['Python 3.4', 'Python 3.5']

    @tpn
    Copy link
    Member Author

    tpn commented Aug 21, 2012

    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.

    @tpn tpn added tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error labels Aug 21, 2012
    @tpn
    Copy link
    Member Author

    tpn commented Aug 21, 2012

    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.

    @tpn
    Copy link
    Member Author

    tpn commented Aug 21, 2012

    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.

    @vstinner
    Copy link
    Member

    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).

    @bitdancer
    Copy link
    Member

    This is 3.3 only, as those tests and the function they test were only introduced in 3.3.

    @bitdancer
    Copy link
    Member

    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.

    @abalkin
    Copy link
    Member

    abalkin commented Aug 22, 2012

    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.

    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Jun 29, 2014

    Are these tests still failing, can this issue be closed as "out of date" or what?

    @vstinner
    Copy link
    Member

    I don't see the issue anymore, I guess that it was fixed.

    @vstinner
    Copy link
    Member

    I mark this issue as a duplicate of bpo-35317.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    tests Tests in the Lib/test dir topic-email type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants