Changes between Initial Version and Version 3 of Ticket #27408


Ignore:
Timestamp:
Nov 1, 2016, 3:22:22 PM (7 years ago)
Author:
Tim Graham
Comment:

I'm not sure if this is a good idea due to magic/complexity, but if we had a patch, we could better evaluate it. I guess your use case doesn't allow constructing B after A.objects.bulk_create()?

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #27408

    • Property Triage Stage UnreviewedSomeday/Maybe
    • Property Summary Multiple consecutive `bulk_create`s with FK.Make QuerySet.bulk_create() populate fields on related models
  • Ticket #27408 – Description

    initial v3  
    1414a = A()
    1515b = B(a=a)  # doesn't set `a_id`, since `a` has no id assigned yet.
    16 A.bulk_create([a])  # sets `a`'s id.
    17 B.bulk_create([b])  # error!
     16A.objects.bulk_create([a])  # sets `a`'s id.
     17B.objects.bulk_create([b])  # error!
    1818}}}
    1919The first `bulk_create` call sets the id on `a`, but `b.a_id` remains `None`.
     
    3535bulk_a = [a]
    3636bulk_b = [b]
    37 A.bulk_create(bulk_a)  # sets `a`'s id.
     37A.objects.bulk_create(bulk_a)  # sets `a`'s id.
    3838fill_foreignkey_ids(bulk_b, ['a'])
    39 B.bulk_create(bulk_b)  # now it works. Lovely.
     39B.objects.bulk_create(bulk_b)  # now it works. Lovely.
    4040}}}
    4141
Back to Top