cidb: retry on exceptions with type name matching OperationalError

BUG=chromium:483654
TEST=None

Change-Id: I66433911713d874adccb45ff3e72e2a8cb9f916d
Reviewed-on: https://chromium-review.googlesource.com/281219
Trybot-Ready: Aviv Keshet <akeshet@chromium.org>
Tested-by: Aviv Keshet <akeshet@chromium.org>
Reviewed-by: Dan Shi <dshi@chromium.org>
Commit-Queue: Aviv Keshet <akeshet@chromium.org>
diff --git a/lib/cidb.py b/lib/cidb.py
index 8288600..1231df6 100644
--- a/lib/cidb.py
+++ b/lib/cidb.py
@@ -58,7 +58,11 @@
   Returns:
     True if the query should be retried, False otherwise.
   """
-  if isinstance(e, sqlalchemy.exc.OperationalError):
+  # Exceptions usually are raised as sqlalchemy.exc.OperationalError, but
+  # occasionally also escape as MySQLdb.OperationalError. Neither of those
+  # exception types inherit from one another, so we fall back to string matching
+  # on the exception name. See crbug.com/483654
+  if 'OperationalError' in str(type(e)):
     error_code = e.orig.args[0]
     if error_code in _RETRYABLE_OPERATIONAL_ERROR_CODES:
       logging.info('Encountered retryable cidb exception %s, retrying....', e)