#23718: TEST_MIRROR setting doesn't work as expected (and has no tests)
-----------------------------------+------------------------------------
     Reporter:  coagulant          |                    Owner:  nobody
         Type:  Bug                |                   Status:  new
    Component:  Testing framework  |                  Version:  1.7
     Severity:  Normal             |               Resolution:
     Keywords:  replica testing    |             Triage Stage:  Accepted
    Has patch:  0                  |      Needs documentation:  0
  Needs tests:  0                  |  Patch needs improvement:  0
Easy pickings:  0                  |                    UI/UX:  0
-----------------------------------+------------------------------------

Comment (by asser):

 Just ran into this, but with raw queries instead. Using the connection
 directly does not work even with {{{TransactionTestCase}}}.

 So for now I'm using this hacky workaround:

 {{{
 #!python
 from django.db import connections

 class ReplicationTestCase(TestCase):
     """
     Redirect raw queries to the replica, ie.

         from django.db import connections

         cursor = connections['replica'].cursor()
         cursor.execute(...)  # Is run directly on master in tests
     """
     def setUp(self):
         super(ReplicationTestCase, self).setUp()
         connections['replica']._orig_cursor =
 connections['replica'].cursor
         connections['replica'].cursor = connections['master'].cursor

     def tearDown(self):
         connections['replica'].cursor =
 connections['replica']._orig_cursor
         super(ReplicationTestCase, self).tearDown()
 }}}

 As an added benefit it works for model managers too even though I'm not
 using {{{TransactionTestCase}}} indicating that the connection might be
 able to be shared in a similar way?

--
Ticket URL: <https://code.djangoproject.com/ticket/23718#comment:10>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.82e7266cd54e680cdbecaf38cf3d9dfe%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to