]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed bug where SQL statement would be improperly ASCII-encoded
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 22 Nov 2013 23:35:36 +0000 (18:35 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 22 Nov 2013 23:37:35 +0000 (18:37 -0500)
when a pre-DBAPI :class:`.StatementError` were raised within
:meth:`.Connection.execute`, causing encoding errors for
non-ASCII statements.  The stringification now remains within
Python unicode thus avoiding encoding errors. [ticket:2871]

Conflicts:
test/engine/test_execute.py

doc/build/changelog/changelog_08.rst
lib/sqlalchemy/engine/base.py
test/engine/test_execute.py
test/sql/test_query.py

index cc51febe1cab4b1c63d41c52129208c1361b5748..e5df476163e7ae8c245ff9877ad2d6c822116d66 100644 (file)
 .. changelog::
     :version: 0.8.4
 
+    .. change::
+        :tags: bug, engine
+        :tickets: 2871
+        :versions: 0.9.0b2
+
+        Fixed bug where SQL statement would be improperly ASCII-encoded
+        when a pre-DBAPI :class:`.StatementError` were raised within
+        :meth:`.Connection.execute`, causing encoding errors for
+        non-ASCII statements.  The stringification now remains within
+        Python unicode thus avoiding encoding errors.
+
     .. change::
         :tags: bug, oracle
         :tickets: 2870
index 25167167d5304dbbf75555c24b26a05f00c49cd0..57d0445dd7ecc3507fbe44d6a4c10a68c2f76ec5 100644 (file)
@@ -824,7 +824,7 @@ class Connection(Connectable):
             context = constructor(dialect, self, conn, *args)
         except Exception, e:
             self._handle_dbapi_exception(e,
-                        str(statement), parameters,
+                        util.text_type(statement), parameters,
                         None, None)
 
         if context.compiled:
index d38b697df75cafd7acd39387333bfbf57cf757bd..76f7b9a71838293464efb49f16e8156138783b7c 100644 (file)
@@ -1,3 +1,4 @@
+# coding: utf-8
 from __future__ import with_statement
 
 from sqlalchemy.testing import eq_, assert_raises, assert_raises_message, \
@@ -11,6 +12,7 @@ from sqlalchemy.sql import column, literal
 from sqlalchemy.testing.schema import Table, Column
 import sqlalchemy as tsa
 from sqlalchemy import testing
+from sqlalchemy import util
 from sqlalchemy.testing import engines
 from sqlalchemy.testing.engines import testing_engine
 import logging.handlers
@@ -227,7 +229,7 @@ class ExecuteTest(fixtures.TestBase):
         def _go(conn):
             assert_raises_message(
                 tsa.exc.StatementError,
-                r"nope \(original cause: Exception: nope\) 'SELECT 1 ",
+                r"nope \(original cause: Exception: nope\) u?'SELECT 1 ",
                 conn.execute,
                     select([1]).\
                         where(
@@ -241,6 +243,23 @@ class ExecuteTest(fixtures.TestBase):
         finally:
             conn.close()
 
+    def test_stmt_exception_non_ascii(self):
+        name = util.u('méil')
+        assert_raises_message(
+            tsa.exc.StatementError,
+            util.u(
+                "A value is required for bind parameter 'uname'"
+                r'.*SELECT users.user_name AS "m\\xe9il"') if util.py2k
+            else
+                util.u(
+                    "A value is required for bind parameter 'uname'"
+                    '.*SELECT users.user_name AS "méil"'),
+            testing.db.execute,
+            select([users.c.user_name.label(name)]).where(
+                            users.c.user_name == bindparam("uname")),
+            {'uname_incorrect': 'foo'}
+        )
+
     def test_stmt_exception_pickleable_no_dbapi(self):
         self._test_stmt_exception_pickleable(Exception("hello world"))
 
index ab689ff0a97bea3780531f65e312cab748c72642..fcd450dbe03783fcbd9c5667f729c88241cf8378 100644 (file)
@@ -68,7 +68,7 @@ class QueryTest(fixtures.TestBase):
             r"A value is required for bind parameter 'user_name', in "
             "parameter group 2 \(original cause: (sqlalchemy.exc.)?InvalidRequestError: A "
             "value is required for bind parameter 'user_name', in "
-            "parameter group 2\) 'INSERT INTO query_users",
+            "parameter group 2\) u?'INSERT INTO query_users",
             users.insert().execute,
             {'user_id':7, 'user_name':'jack'},
             {'user_id':8, 'user_name':'ed'},