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

Fix for REUSE_DB problems #101

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Fix for REUSE_DB problems #101

wants to merge 3 commits into from

Conversation

alexjg
Copy link
Contributor

@alexjg alexjg commented Oct 21, 2012

I had a look into the specific problem on my machine. The essential problem is that several db backends cache their underlying connection. The nose test runner detects whether a new database is needed by calling cursor() on the backend after renaming the NAME field of the settings dictionary which the backend uses, this fails if the database does not exist, allowing nose to decide to create the database.

Unfortunately some backends cache their underlying connection objects so if any code connects to the database (which hasn't been renamed by django-nose yet) before nose does then any subsequent cursor() calls will succeed (as they use the cached connection) and nose is unable to detect that the database exists. The attached code fixes that.

Fixes #76

dvelyk and others added 2 commits September 27, 2012 01:53
…k_works'" AttributeError when attempting to run django_nose tests with REUSE_DB=1 on Django trunk (pre-v1.5)

The confirm method has been removed from BaseDatabaseFeatures as cached properties (like "supports_transactions") now confirm their features automagically.
@erikrose
Copy link
Contributor

If this really fixes it, you've made my day! :-) Unfortunately, I've lost the ability to reproduce it. Do you happen to have a reduced (or even non-reduced) test case?

@alexjg
Copy link
Contributor Author

alexjg commented Oct 22, 2012

Well it's solving the problem for me but unfortunately the code base is a clients website. I'll try and extract a configuration which reproduces the problem in the next few days.

@dcramer
Copy link
Contributor

dcramer commented Oct 23, 2012

FWIW this is how we solve these things.

for conn in connections.all(): conn.close

@alexjg
Copy link
Contributor Author

alexjg commented Oct 24, 2012

Yeah that seems like a much more sensible approach.

@akaihola
Copy link
Contributor

akaihola commented Jan 9, 2013

@dcramer Where did you do the conn.close() calls?

On an old project which runs on Django 1.3.1, I just can't figure out why django-nose creates and syncdbs a test_myproject database, but tries to run the tests on myproject. I've tried different combinations of NAME and TEST_NAME in settings.DATABASES but haven't found any working combination.

dullaran added a commit to tourlines/django-nose that referenced this pull request May 30, 2014
cmyers734 pushed a commit to newfoundry/django-nose that referenced this pull request Sep 8, 2014
for bug jazzband#76

When REUSE_DB=1, the test suite would end up using the non-test database
@jwhitlock jwhitlock added this to the Fix REUSE_DB=1 milestone Jul 7, 2015
@jwhitlock jwhitlock added the bug label Aug 5, 2015
jwhitlock pushed a commit that referenced this pull request Oct 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

Successfully merging this pull request may close these issues.

REUSE_DB causes it to use the non-test DBs?
6 participants