Skip to content

Commit d0f96ff

Browse files
committed
Return in case of higher precision than expected
1 parent f7bb72e commit d0f96ff

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

MySQLdb/times.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ def DateTime_or_None(s):
6161
# 12:00:00.123456
6262
micros = int(micros) * 10 ** (6 - len(micros))
6363
else:
64-
# 12:00:00.123456789
65-
micros = int(micros)
64+
return None
6665

6766
return datetime(
6867
int(s[:4]), # year

tests/test_MySQLdb_times.py

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def test_date_or_none(self):
1919
assert times.Date_or_None('fail') is None
2020
assert times.Date_or_None('2015-12') is None
2121
assert times.Date_or_None('2015-12-40') is None
22+
assert times.Date_or_None('0000-00-00') is None
2223

2324
def test_time_or_none(self):
2425
assert times.Time_or_None('00:00:00') == time(0, 0)
@@ -44,6 +45,8 @@ def test_datetime_or_none(self):
4445

4546
assert times.DateTime_or_None('') is None
4647
assert times.DateTime_or_None('fail') is None
48+
assert times.DateTime_or_None('0000-00-00 00:00:00') is None
49+
assert times.DateTime_or_None('0000-00-00 00:00:00.000000') is None
4750
assert times.DateTime_or_None('2015-12-13T01:02:03.123456789') is None
4851

4952
def test_timedelta_or_none(self):

0 commit comments

Comments
 (0)