Opened 16 years ago

Closed 16 years ago

#6665 closed (worksforme)

test.utils.create_test_db cannot drop existing test database when using MySQL

Reported by: Daniel Eloff <dan.eloff@…> Owned by: nobody
Component: Testing framework Version: dev
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

If the test database is not removed during the previous test run, then django will try to drop it and recreate it. With MySQL this yields:

Got an error recreating the test database: (1192, "Can't execute the given command because you have active locked tables or an active transaction")

I fixed this by closing the connection and creating a new one before the execution of the DROP command.

connection.close()
from django.db import connection
cursor = connection.cursor()
cursor.execute("DROP DATABASE %s" % qn(TEST_DATABASE_NAME))

Doing this requires adding a "global connection" to the top of the create_test_db function.

Change History (1)

comment:1 by Russell Keith-Magee, 16 years ago

Has patch: unset
Resolution: worksforme
Status: newclosed

I can't reproduce this error; Even when I hard crash a test run using CTRL-C, I get prompted to remove the old database, which happens without any problem. This is using MySQL 5.0 and MySQLdb 1.2.2. If you can provide more explicit instructions on how to replicate this error (including your test environment), feel free to reopen the ticket.

However, accepting that the problem could exist, I can't see how the patch you suggest will fix anything. At the times at which DROP DATABASE is called, you have either just finished running a set of tests, or you are just about to start; as far as I can make out, there can't be a cursor lock in place. If you can provide your suggested change as a diff, rather than a block of code in a comment, it might help me understand what you have in mind here.

Note: See TracTickets for help on using tickets.
Back to Top