#23273: MigrationRecorder does not obey db_router allow_migrate rules
----------------------------+--------------------------------------
     Reporter:  froomzy     |                    Owner:  nobody
         Type:  Bug         |                   Status:  new
    Component:  Migrations  |                  Version:  1.7-rc-2
     Severity:  Normal      |               Resolution:
     Keywords:              |             Triage Stage:  Unreviewed
    Has patch:  0           |      Needs documentation:  0
  Needs tests:  0           |  Patch needs improvement:  0
Easy pickings:  0           |                    UI/UX:  0
----------------------------+--------------------------------------

Comment (by froomzy):

 @jarshwah: I don't think it is the router. Mainly because the router is
 not called at this point. Which is what I believe is the bug.

 @akaariai: I agree that there are similarities. Surely I should be able to
 manage which connections I actually run migrations against. That seems to
 be what the db_router is trying to do.

 I thought that something like the following would solve our problem:

 {{{
     from django.db import router

         .
         .
         .

     def ensure_schema(self):
         """
         Ensures the table exists and has the correct schema.
         """
         # If the table's there, that's fine - we've never changed its
 schema
         # in the codebase.
         if self.Migration._meta.db_table in
 self.connection.introspection.get_table_list(self.connection.cursor()):
             return
         # Make the table
         # Change below, similar to how allowed_to_migrate in
 django/db/migrations/operations/base.py works
         if router.allow_migrate(self.connection, self.Migration):
                 with self.connection.schema_editor() as editor:
                         editor.create_model(self.Migration)
 }}}

 But this means that changes to applied_migrations, record_applied, and
 record_unapplied need to be made, so that it doesn't try to write to a
 none existent table.

 For us this is not an urgent issue, as we have appropriate permissions to
 those connections that are not our core connection. But I do have a
 concern for any time that we are using a true read-only connection, where
 we do not have the CREATE TABLE permission. Because this code, as it
 exists, will blow up in this situation. I tested that with a read-only
 connection in our db setup, and got an insufficient permissions error.

 Thanks,
 Dylan

-- 
Ticket URL: <https://code.djangoproject.com/ticket/23273#comment:3>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.9488196ad2d51c06e783b464307e81b5%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to