Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sqlite_utils/recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def parsedate(
.date()
.isoformat()
)
except parser.ParserError:
except (parser.ParserError, OverflowError):
if errors is IGNORE:
return value
elif errors is SET_NULL:
Expand All @@ -58,7 +58,7 @@ def parsedatetime(
return value
try:
return parser.parse(value, dayfirst=dayfirst, yearfirst=yearfirst).isoformat()
except parser.ParserError:
except (parser.ParserError, OverflowError):
if errors is IGNORE:
return value
elif errors is SET_NULL:
Expand Down
24 changes: 24 additions & 0 deletions tests/test_recipe_overflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import pytest

from sqlite_utils import recipes


OVERFLOWING_DATE = "999999999999999999999999999999-01-01"


@pytest.mark.parametrize("fn", ("parsedate", "parsedatetime"))
def test_dateparse_overflow_raises_by_default(fn):
with pytest.raises(OverflowError):
getattr(recipes, fn)(OVERFLOWING_DATE)


@pytest.mark.parametrize("fn", ("parsedate", "parsedatetime"))
@pytest.mark.parametrize(
"errors,expected",
(
(recipes.IGNORE, OVERFLOWING_DATE),
(recipes.SET_NULL, None),
),
)
def test_dateparse_overflow_respects_errors(fn, errors, expected):
assert getattr(recipes, fn)(OVERFLOWING_DATE, errors=errors) == expected
Loading