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

Comment (by pachewise):

 Hi Team,

 We also noticed an issue here which happens when you have a default +
 read_replica config, and you have a router that only selects a
 read_replica when considering particular models. If you have those
 conditions, _and_ a data migration that uses both Job and User, you will
 have issues because the "default" connection config will be pointing to
 your `test_myschema`, whereas the `read_replica` config will still be
 pointing to `myschema`.

 e.g.,


 {{{
 models.py:
 Job:
    user_id := FK(User)

 DBRouter:
    db_for_write := 'read_replica' if model == Job else 'default'

 settings:
    DATABASES = {
          'default': { ... },
          'read_replica': {
                 # <configs>...
                 'TEST': {'MIRROR': 'default'}
           }
     }


 0001_migration.py:
     # ...
     for job in Job.objects.all():  # using apps.get_model()
         job.user.id  # will error out with __fake__.DoesNotExist
 }}}


 In the case above, if your "live" read_replica schema has any job data, it
 will try to run that last line, but there won't be any Users in the
 `test_schema` to match to.

 Not sure if ''we're'' doing something wrong, but just letting you know
 that there are cases where a custom DBrouter could route to a config that
 ''should'' be a test mirror, but isn't.

 Using python 3.6, Django 1.11.20, MySQL 5.7

-- 
Ticket URL: <https://code.djangoproject.com/ticket/23718#comment:23>
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.4d247397cad7db9cfd6a69bedd911c7e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to