Mike Bayer avatar Mike Bayer committed ab55347

more fixes to bound parameter exception reporting

Comments (0)

Files changed (3)

 
 - sql
     - Repaired the printing of SQL exceptions which are not 
-      based on parameters.
+      based on parameters or are not executemany() style.
       
 - postgres
     - Deprecated the hardcoded TIMESTAMP function, which when

lib/sqlalchemy/exc.py

         self.connection_invalidated = connection_invalidated
 
     def __str__(self):
-        if self.params and len(self.params) > 10:
+        if isinstance(self.params, (list, tuple)) and len(self.params) > 10 and isinstance(self.params[0], (list, dict, tuple)):
             return ' '.join((SQLAlchemyError.__str__(self),
                              repr(self.statement),
                              repr(self.params[:2]),
-                             '... and a total of %i bound parameters' % len(self.params)))
+                             '... and a total of %i bound parameter sets' % len(self.params)))
         return ' '.join((SQLAlchemyError.__str__(self),
                          repr(self.statement), repr(self.params)))
 

test/base/except.py

                 'this is a message', None, OperationalError())
         except sa_exceptions.DBAPIError, exc:
             assert str(exc) == "(OperationalError)  'this is a message' None"
+
+    def test_tostring_large_dict(self):
+        try:
+            raise sa_exceptions.DBAPIError.instance(
+                'this is a message', {'a':1, 'b':2, 'c':3, 'd':4, 'e':5, 'f':6, 'g':7, 'h':8, 'i':9, 'j':10, 'k':11}, OperationalError())
+        except sa_exceptions.DBAPIError, exc:
+            assert str(exc).startswith("(OperationalError)  'this is a message' {")
+
+    def test_tostring_large_list(self):
+        try:
+            raise sa_exceptions.DBAPIError.instance(
+                'this is a message', [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], OperationalError())
+        except sa_exceptions.DBAPIError, exc:
+            assert str(exc).startswith("(OperationalError)  'this is a message' [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]")
+
+    def test_tostring_large_executemany(self):
+        try:
+            raise sa_exceptions.DBAPIError.instance(
+                'this is a message', [{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},], OperationalError())
+        except sa_exceptions.DBAPIError, exc:
+            assert str(exc) == "(OperationalError)  'this is a message' [{1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}]", str(exc)
+
+        try:
+            raise sa_exceptions.DBAPIError.instance(
+                'this is a message', [{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},], OperationalError())
+        except sa_exceptions.DBAPIError, exc:
+            assert str(exc) == "(OperationalError)  'this is a message' [{1: 1}, {1: 1}] ... and a total of 11 bound parameter sets"
+
+        try:
+            raise sa_exceptions.DBAPIError.instance(
+                'this is a message', [(1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,)], OperationalError())
+        except sa_exceptions.DBAPIError, exc:
+            assert str(exc) == "(OperationalError)  'this is a message' [(1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,)]"
+
+        try:
+            raise sa_exceptions.DBAPIError.instance(
+                'this is a message', [(1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), ], OperationalError())
+        except sa_exceptions.DBAPIError, exc:
+            assert str(exc) == "(OperationalError)  'this is a message' [(1,), (1,)] ... and a total of 11 bound parameter sets"
         
     def test_db_error_busted_dbapi(self):
         try:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.