Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not created test DB for default alias if used REUSE_DB=1. #87

Open
vstepanov opened this issue Aug 1, 2012 · 4 comments
Open

not created test DB for default alias if used REUSE_DB=1. #87

vstepanov opened this issue Aug 1, 2012 · 4 comments
Labels

Comments

@vstepanov
Copy link

I tried to use REUSE_DB=1 python manage.py test, but test DB for default alias wasn't created, because django_nose-1.1-py2.7.egg/django_nose/runner.py:_should_create_database believes that the database already exists.

I investigated this and saw that connection.cursor() in _should_create_database doesn't raise exception for connection to default DB, which was renamed to test db name.

However, if the connection was closed before calling the connection.cursor(), the exception is raised for nonexistent DBs and isn't raised for the existing (ie the correct behavior).

Perhaps before calling _should_create_database, the connection should be closed, is not it?

My settings file contains:

DATABASES = {
    'default': {
            'NAME': 'projects',
            'ENGINE': 'django.db.backends.mysql',
            'USER': 'user',
            'PASSWORD': '',
            'SUPPORTS_TRANSACTIONS': True,
            'OPTIONS': {
                'init_command':"SET time_zone = ' 0:00'",
                'charset': 'utf8',
            },
        },
    'tts': {
            'NAME': 'stats',
            'ENGINE': 'django.db.backends.mysql',
            'USER': 'user',
            'PASSWORD': '',
            'SUPPORTS_TRANSACTIONS': True,
            'OPTIONS': {
                'init_command':"SET time_zone = ' 0:00'",
                'charset': 'utf8',
            },
        },
    'ppk': {
            'NAME': 'stats',
            'ENGINE': 'django.db.backends.mysql',
            'USER': 'root',
            'PASSWORD': '',
            'SUPPORTS_TRANSACTIONS': True,
            'OPTIONS': {
                'init_command':"SET time_zone = ' 0:00'",
                'charset': 'utf8',
            },
        },
    'stp': {
            'NAME': 'manager',
            'ENGINE': 'django.db.backends.mysql',
            'USER': 'root',
            'PASSWORD': '',
            'SUPPORTS_TRANSACTIONS': True,
            'OPTIONS': {
                'charset': 'utf8',
            },
        },
}

Versions:
django==1.4
django_nose==1.1
MySQL_python==1.2.3
Python==2.7.3
OS - Ubuntu x86_64 3.2.0-27-generic
mysql server - percona-server-server-5.5

these changes have fixed the issue:

diff --git a/django_nose/runner.py b/django_nose/runner.py
index 18df494..a87e07e 100644
--- a/django_nose/runner.py
+++ b/django_nose/runner.py
@@ -276,17 +276,10 @@ class NoseTestSuiteRunner(BasicNoseRunner):
             orig_db_name = connection.settings_dict['NAME']
             connection.settings_dict['NAME'] = test_db_name

+            connection.close()
             if _should_create_database(connection):
                 # We're not using _skip_create_test_db, so put the DB name back:
                 connection.settings_dict['NAME'] = orig_db_name
-
-                # Since we replaced the connection with the test DB, closing
-                # the connection will avoid pooling issues with SQLAlchemy. The
-                # issue is trying to CREATE/DROP the test database using a
-                # connection to a DB that was established with that test DB.
-                # MySQLdb doesn't allow it, and SQLAlchemy attempts to reuse
-                # the existing connection from its pool.
-                connection.close()
             else:
                 # Reset auto-increment sequences. Apparently, SUMO's tests are
                 # horrid and coupled to certain numbers.
@vstepanov
Copy link
Author

Yep. And _mysql_reset_sequences returns list of SQL statements for non-test DBs.

@erikrose
Copy link
Contributor

erikrose commented Aug 6, 2012

Right. There is a patch for that I have to merge in.

@benjaoming
Copy link

I believe the patch is #101

@ryanbagwell
Copy link

Can we get this patch merged?

@jwhitlock jwhitlock added the bug label Jul 7, 2015
@jwhitlock jwhitlock added this to the Fix REUSE_DB=1 milestone Jul 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants