aaug...@bcc190cf-cafb-0310-a4f2-bffc1f526a37  committed 0c0b8fc

Fixed #17513 -- Prevented the MySQL backend from leaking MySQLdb-specific exceptions. Thanks Claude Paroz.

  • Participants
  • Parent commits cebf2b6

Comments (0)

Files changed (2)

File django/db/backends/mysql/

             # misclassified and Django would prefer the more logical place.
             if e[0] in self.codes_for_integrityerror:
                 raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]
-            raise
+            raise utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2]
         except Database.DatabaseError, e:
             raise utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2]

File tests/regressiontests/backends/

         self.assertTrue(hasattr(connection.ops, 'connection'))
         self.assertEqual(connection, connection.ops.connection)
+    def test_duplicate_table_error(self):
+        """ Test that creating an existing table returns a DatabaseError """
+        cursor = connection.cursor()
+        query = 'CREATE TABLE %s (id INTEGER);' % models.Article._meta.db_table
+        with self.assertRaises(DatabaseError):
+            cursor.execute(query)
 # We don't make these tests conditional because that means we would need to
 # check and differentiate between: