Description
ConnectionHandler (django.db.connections
is an instance of this) caches, so I ended up with with problems due to using connection from the old config† after changing settings from a django_db_modify_db_settings
fixture. I fixed my issue by calling the following code before+after the fixture:
def clear_caches():
"""Invalidate the connection caches."""
connections._connections = threading.local()
# this will clear the cached property
del connections.databases
If there isn't any disagreement I will submit a PR for this to change the default fixture and also update the documentation.
This looks like it should work back to at least 1.7.x, I haven't checked back further. Is there an officially supported range of Django versions?
† in my case I was only getting the database which was configured in DJANGO_SETTINGS_MODULE
, I am not sure if that was because of app code causing a query too soon, or if it is expected every time in Django (in 1.11.11)