#23749: migrations.RunPython broken with dbrouters.
---------------------------------+---------------------------------
     Reporter:  alfredperlstein  |      Owner:  nobody
         Type:  Bug              |     Status:  new
    Component:  Migrations       |    Version:  1.7
     Severity:  Normal           |   Keywords:  migrations dbrouter
 Triage Stage:  Unreviewed       |  Has patch:  0
Easy pickings:  0                |      UI/UX:  0
---------------------------------+---------------------------------
 It seems that the migration system in 1.7 does not properly query the
 dbrouter setup when a migrations.RunPython method is invoked.

 Running the following command:
 {{{
 python manage.py migrate mycompany --noinput --traceback --database=logs
 --verbosity=2
 }}}

 Never seems to call the router for the following migration, so as you can
 see I've added code to parse sys.argv as an experiment which seems to
 sort-of work, but really looks like the wrong way to do this.

 {{{
 # -*- coding: utf-8 -*-
 from __future__ import unicode_literals

 from django.db import models, migrations
 from applianceUI.mycompany.dbrouter import LogRouter
 import sys

 def bkd_default_ports(apps, schema_editor):
     db = None
     for arg in sys.argv:
         if '=' not in arg:
             continue
         print "arg: ",  arg
         k, v = arg.split('=', 2)
         print "k: '%s', v: '%s'  " % (k,v)

         if k == "--database":
             print arg
             db = v
             break

     print "db is %s" % db
     router = LogRouter()
     Blockd = apps.get_model("mycompany", "Blockd")

     if router.allow_migrate(db, Blockd) is False:
         return

     try:
         bkd = Blockd.objects.order_by("-id")[0]
     except IndexError:
         bkd = Blockd.objects.create()
     if bkd.bkd_ports is "":
         bkd.bkd_ports = "80, 8080, 3128"
         bkd.save()


 class Migration(migrations.Migration):

     dependencies = [
         ('mycompany', '0005_auto_direction_and_indexes'),
     ]

     operations = [
         migrations.RunPython(bkd_default_ports),
     ]
 }}}

 The arguments apps and schema_editor didn't give me enough data to make my
 decision.  How can i properly derive that the database is "logs"?

--
Ticket URL: <https://code.djangoproject.com/ticket/23749>
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/058.fcdc5c4eb6da32d67646d622d2a27c2b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to