Opened 18 years ago

Closed 16 years ago

#3418 closed (invalid)

MSSQL and OverflowError for django/utils/tzinfo.py

Reported by: Jaroslaw Zabiello Owned by: nobody
Component: Tools Version: dev
Severity: Keywords: ado_mssql datetime overflow
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

Exception Type:  	OverflowError
Exception Value: 	mktime argument out of range
Exception Location: 	C:\opt\Python25\lib\site-packages\django\utils\tzinfo.py in _isdst, line 50

This kind of errors appears when you work with SQL Server (or transfered data from MSSQL to MySQL). SQL Server converts NULLs in its datetime field into year 1900! And this raise exception OverflowError with message "mktime argument out of range" for pythonic function time.mktime() used in utils/tzinfo.py at line 50:

def _isdst(self, dt):
    tt = (dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.weekday(), 0, -1)
    stamp = time.mktime(tt)
    tt = time.localtime(stamp)
    return tt.tm_isdst > 0

This is monkey patched code which solves this problem:

def _isdst(self, dt):
    year = dt.year
    if year == 1900: # or < 1970
        year = 1970
    tt = (year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.weekday(), 0, -1)
    stamp = time.mktime(tt)
    tt = time.localtime(stamp)
    return tt.tm_isdst > 0

Used Django SVN rev.4455, WinXP Pro.

Change History (5)

comment:1 by Gary Wilson <gary.wilson@…>, 18 years ago

Patch needs improvement: set
Triage Stage: UnreviewedDesign decision needed

needs discussion on the best way to solve this.

comment:2 by Malcolm Tredinnick, 18 years ago

If the problem is that NULLs are stored in the database and then lifted up to Python in a way we don't handle, I do not like the proposed solution. NULL date/time database values should end up being None values at the Python level. Not some random 1970 date.

Or is the problem that the values are stored as 1900 dates?

I don't use Windows or have access to MSSQL, so if somebody with more information could fill in some gaps here, that would be great.

comment:3 by Adam Vandenberg, 17 years ago

Recommend "won't fix" on this; SQL Server supports NULL datetime fields.
It's possible that this is related to the SQL Server backend using 'smalldatetime' types instead of 'datetime' types.
But without a repro case or test it's hard to tell what's even going on here.

comment:4 by Jacob, 17 years ago

Keywords: ado_mssql added; mssql removed

comment:5 by Adam Vandenberg, 16 years ago

Resolution: invalid
Status: newclosed

Marking as invalid since the SQL Server backend has been removed. If the reported finds this issue against one of the 3rd party SQL Server backends, those maintainers would probably appreciate bug reports in their trackers.

Note: See TracTickets for help on using tickets.
Back to Top