]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fix mysql+gaerdbms dialect for changed exception format
authorDan Ring <dfring@gmail.com>
Sat, 20 Apr 2013 01:01:39 +0000 (18:01 -0700)
committerDan Ring <dfring@gmail.com>
Sat, 20 Apr 2013 01:01:39 +0000 (18:01 -0700)
googleappengine v1.7.5 changed the exception format to be
incompatible with MySQLDialect_gaerdbms#_extract_error_code

This fix works for both old- and new-style exceptions.

Changes causing the breakage:
/trunk/python/google/storage/speckle/python/api/rdbms.py
at
https://code.google.com/p/googleappengine/source/detail?r=318

lib/sqlalchemy/dialects/mysql/gaerdbms.py

index a93a78b738c8f9e2f285e8697eea4bce5170120a..ad0ce763857b20daaf55e6dd9602b52c0511faeb 100644 (file)
@@ -65,10 +65,10 @@ class MySQLDialect_gaerdbms(MySQLDialect_mysqldb):
         return [], opts
 
     def _extract_error_code(self, exception):
-        match = re.compile(r"^(\d+):").match(str(exception))
+        match = re.compile(r"^(\d+):|^\((\d+),").match(str(exception))
         # The rdbms api will wrap then re-raise some types of errors
         # making this regex return no matches.
-        code = match.group(1) if match else None
+        code = match.group(1) or match.group(2) if match else None
         if code:
             return int(code)