From: Mike Bayer Date: Thu, 4 Aug 2011 19:34:24 +0000 (-0400) Subject: - Ensured that the same ValueError is raised for X-Git-Tag: rel_0_7_3~100 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=757400f82ff079f029cf2e11536c13d6199f832d;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Ensured that the same ValueError is raised for illegal date/time/datetime string parsed from the database regardless of whether C extensions are in use or not. --- diff --git a/CHANGES b/CHANGES index ff74044c49..77f041c86e 100644 --- a/CHANGES +++ b/CHANGES @@ -15,6 +15,12 @@ CHANGES when the Session.is_active is True. [ticket:2241] +- sqlite + - Ensured that the same ValueError is raised for + illegal date/time/datetime string parsed from + the database regardless of whether C + extensions are in use or not. + 0.7.2 ===== - orm diff --git a/lib/sqlalchemy/processors.py b/lib/sqlalchemy/processors.py index cb5f00bdef..dd789a44eb 100644 --- a/lib/sqlalchemy/processors.py +++ b/lib/sqlalchemy/processors.py @@ -24,7 +24,10 @@ def str_to_datetime_processor_factory(regexp, type_): if value is None: return None else: - return type_(*map(int, rmatch(value).groups(0))) + m = rmatch(value) + if m is None: + raise ValueError("Couldn't parse %s string." % type_.__name__) + return type_(*map(int, m.groups(0))) return process def boolean_to_int(value): diff --git a/test/dialect/test_sqlite.py b/test/dialect/test_sqlite.py index f3422cf0e1..c4748500ae 100644 --- a/test/dialect/test_sqlite.py +++ b/test/dialect/test_sqlite.py @@ -44,11 +44,25 @@ class TestTypes(fixtures.TestBase, AssertsExecutionResults): finally: meta.drop_all() - def test_string_dates_raise(self): + def test_string_dates_passed_raise(self): assert_raises(exc.StatementError, testing.db.execute, select([1]).where(bindparam('date', type_=Date)), date=str(datetime.date(2007, 10, 30))) + def test_cant_parse_datetime_message(self): + for (typ, disp) in [ + (Time, "time"), + (DateTime, "datetime"), + (Date, "date") + ]: + assert_raises_message( + ValueError, + "Couldn't parse %s string." % disp, + lambda: testing.db.execute( + text("select 'ASDF' as value", typemap={"value":typ}) + ).scalar() + ) + def test_time_microseconds(self): dt = datetime.datetime(2008, 6, 27, 12, 0, 0, 125, ) eq_(str(dt), '2008-06-27 12:00:00.000125')