#30690: get_or_create() ignores database router's db_for_read() method
-------------------------------------+-------------------------------------
               Reporter:  Maciej     |          Owner:  nobody
  Olko                               |
                   Type:             |         Status:  new
  Uncategorized                      |
              Component:  Database   |        Version:  2.2
  layer (models, ORM)                |       Keywords:  router, database-
               Severity:  Normal     |  router, get_or_create
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 {{{
 class Foo(models.Model):  # model in `legacy` app
     bar = models.CharField()

 class FizRouter:
     @staticmethod
     def db_for_read(model, **hints):
         if model._meta.app_label == 'legacy':
             return 'legacy'
         return 'default'

     @staticmethod
     def db_for_write(model, **hints):
         return 'default'

 # file: settings.py
 DATABASE_ROUTERS = ['path.FizRouter']
 }}}

 `Foo.objects.get_or_create()` will hit `default` database no matter if
 requested object is in `legacy` database.
 I would assume that we would try to get object from `legacy` database and
 create in `default` if not found.

 As far as I'm concerned current behaviour is not documented, IMHO it
 should be, if current behaviour is desired.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30690>
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/050.ac2d3644f54cc6eed873e02f278a42d3%40djangoproject.com.

Reply via email to