]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Ensured that the same ValueError is raised for
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 4 Aug 2011 19:34:24 +0000 (15:34 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 4 Aug 2011 19:34:24 +0000 (15:34 -0400)
    illegal date/time/datetime string parsed from
    the database regardless of whether C
    extensions are in use or not.

CHANGES
lib/sqlalchemy/processors.py
test/dialect/test_sqlite.py

diff --git a/CHANGES b/CHANGES
index ff74044c498a72f2846afe90a68f4fee2a352a68..77f041c86efa669a89013f2122af5d4c105f8d74 100644 (file)
--- 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
index cb5f00bdefa72c9400ecdc5b95363c67b3ee1e2e..dd789a44ebdd8f8d304bf5d3bbc668407f1912ca 100644 (file)
@@ -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):
index f3422cf0e1d699101246e7f2432908ed712c7bed..c4748500aefcdec1b9cbb873a8e4adf7140021b3 100644 (file)
@@ -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')