#33649: bulk_create() with ignore_conflicts=True and ForeignKey fails
-------------------------------------+-------------------------------------
     Reporter:  Markus Friedrich     |                    Owner:  nobody
         Type:  Bug                  |                   Status:  closed
    Component:  Database layer       |                  Version:  3.2
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  invalid
     Keywords:  bulk_create          |             Triage Stage:
  ForeignKey ignore_conflicts        |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Markus Friedrich):

 Thanks for you very fast answer and the provided links.

 I know that ignore_conflicts=True disables setting the primary key for all
 DB's and that some DB's are not able to set the primary key using
 bulk_create at all.
 That's why the ForeignKey of Article does not use the primary key (id) of
 Reporter as to_field but used the uuid field of Reporter. This uuid field
 is unique=True and its value is a UUID4 value which is even set if the
 object is not already saved. This enables the use of bulk_create even for
 DB's which are not able to set a primary auto inc key.

 I found now that may test case even fails with the same error with >=3.2
 if ignore_conflicts is removed if a DB is used which cannot set the pk in
 bulk_create. (e.g. older sqlite3 (I have tested with sqlite3-3.27))
 This means with this error message you have intentionally completely
 removed the functionality to use bulk_create together with a ForeignKey on
 all databases which are not able to set the pk in bulk_create!
 If this is really intended I'm OK with it and need to workaround this.
 (even thought I do not understand why there should be a data-loss problem
 in this case (with a uuid as to_field of the ForeignKey))

 (I also do not understand your last sentence: I do not have any already
 saved reporter in my test case (but in my real case). But as detected now
 it even fails without the ignore_conflicts, see above)

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33649#comment:2>
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/010701803bccdd6e-ec065176-7d73-43b4-a2a0-9002baf39d6a-000000%40eu-central-1.amazonses.com.

Reply via email to