diff --git a/apps/sumo/tests/test__utils.py b/apps/sumo/tests/test__utils.py index 47945c9c2c1..10f13ce8877 100644 --- a/apps/sumo/tests/test__utils.py +++ b/apps/sumo/tests/test__utils.py @@ -24,6 +24,10 @@ def test_wrong_type(self): eq_(0, smart_int(None)) eq_(10, smart_int([], 10)) + def test_large_values(self): + """Makes sure ints that would cause an overflow result in fallback.""" + eq_(0, smart_int('1' * 1000)) + class GetNextUrlTests(TestCase): def setUp(self): diff --git a/apps/sumo/utils.py b/apps/sumo/utils.py index edc99bec5b9..00ebc6a4a9d 100644 --- a/apps/sumo/utils.py +++ b/apps/sumo/utils.py @@ -55,7 +55,7 @@ def smart_int(string, fallback=0): """Convert a string to int, with fallback for invalid strings or types.""" try: return int(float(string)) - except (ValueError, TypeError): + except (ValueError, TypeError, OverflowError): return fallback