Hi everyone,

I found a weird behaviour when I run my Django tests, it doesn't always use 
the test database, sometimes it uses the production database and truncate 
it!

I looked at the Django source code and the cause of this behaviour seems to 
be in  'django/test/utils.py' in 'setup_databases()' where a test database 
is created (line 183) only for the first alias, the other connections are 
set as mirrors of the first one (line 198). 

The connection mirroring is done in 'django/db/backends/base/creation.py' 
in 'set_as_test_mirror()' where only the name in the settings dictionary is 
changed, the connection is not reinitialised which causes the connection to 
still point on the production database, adding 'self.connection.close()' 
 before the settings dictionary affectation fixes the issue.

Did any of you has experienced this issue before?

Let me know what you think about it before I create a bug report.

Thanks in advance,

Sylvain

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b4621f0f-c71b-4055-9a06-29fe1e51af14%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to