Skip to content

Commit

Permalink
Close current database connections
Browse files Browse the repository at this point in the history
Issue #76 pull request #101
  • Loading branch information
eroninjapan authored and jwhitlock committed Oct 7, 2015
1 parent 498d32f commit a893caf
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion django_nose/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,9 @@ def _should_create_database(connection):
# Connections are cached by some backends, if other code has connected
# to the database previously under a different database name the
# cached connection will be used and no exception will be raised.
# Setting to null here solves that problem.
# Avoiding this by closing connections and setting to null
for connection in connections.all():
connection.close()
connection.connection = None
connection.cursor()
except Exception: # TODO: Be more discerning but still DB agnostic.
Expand Down

1 comment on commit a893caf

@aaronelliotross
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The loop is clobbering the connection parameter, and with multiple connections, testing the wrong connection after the loop.

Given that the calling code is looping over the connections, I don't think there's any need to loop here, closing the passed connection should be enough.

I'm sorry I don't have a test case, just discovered this debugging why REUSE_DB=1 stopped working for us after upgrading.

Please sign in to comment.