#32323: Lazy object id fetch on object initialization.
-------------------------------------+-------------------------------------
               Reporter:             |          Owner:  nobody
  Bartłomiej Nowak                   |
                   Type:  New        |         Status:  new
  feature                            |
              Component:  Database   |        Version:  2.2
  layer (models, ORM)                |       Keywords:  bulk_create, fetch
               Severity:  Normal     |  id, lazy id fetch,
           Triage Stage:             |  can_return_ids_from_bulk_insert
  Unreviewed                         |      Has patch:  0
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 Let's assume I am using the Postgres database, so the flag
 **can_return_ids_from_bulk_insert** is True.

 I would like to do this:
 {{{
 class ModelA:
       pass

 class ModelB:
       a = models.ForeginKey(ModelA)

 a_to_create = []
 b_to_create = []
 for _ in some_data:
     a = ModelA(...)
     a_to_create.append(a)
     b_to_create.append(
           ModelB(a=a, ...)
      )

 ModelA.objects.bulk_create(a_to_create)
 # all objects in the a_to_create list have now ids, becouse of
 can_return_ids_from_bulk_insert flag. a_to_create[0].id will return int.
 ModelA.objects.bulk_create(b_to_create)
 }}}

 But when I initialize ModelB(a=a), Django immediately fetches id from
 object **a**, which is None in this line, and using this latter, instead
 of fetching it (id) from the provided object, when it's going to create.
 Why do not fetch this id lazy?

 Because of this situation, I have to do an additional loop for every
 additional model.


 Thank you

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32323>
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/052.23b1da0eb2a764e4146bdb9e7afaad49%40djangoproject.com.

Reply via email to