diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-08-04 15:34:24 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-08-04 15:34:24 -0400 |
| commit | 757400f82ff079f029cf2e11536c13d6199f832d (patch) | |
| tree | 4f80ec9ae7c9a006326b84ae948e2f5bb358ad10 | |
| parent | 0eb06660ce838b23e8d12c460f3f322ba3f23ab5 (diff) | |
| download | sqlalchemy-757400f82ff079f029cf2e11536c13d6199f832d.tar.gz | |
- 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.
| -rw-r--r-- | CHANGES | 6 | ||||
| -rw-r--r-- | lib/sqlalchemy/processors.py | 5 | ||||
| -rw-r--r-- | test/dialect/test_sqlite.py | 16 |
3 files changed, 25 insertions, 2 deletions
@@ -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 cb5f00bde..dd789a44e 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 f3422cf0e..c4748500a 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') |
