Fixed #28668 -- Support ignoring conflicts with bulk_create()#9192
Fixed #28668 -- Support ignoring conflicts with bulk_create()#9192timgraham merged 1 commit intodjango:masterfrom orf:28668-on-conflict
Conversation
django/db/models/query.py
Outdated
| _batched_insert() the remaining objects again. | ||
| """ | ||
| if on_conflict == 'ignore' and not connections[self.db].features.supports_on_conflict_ignore: | ||
| raise ValueError('This database backend does not support ON CONFLICT IGNORE') |
timgraham
left a comment
There was a problem hiding this comment.
Target release notes for 2.2. and add supports_on_conflict_ignore to the release notes in "Backwards incompatible changes" similar to the existing note that's there.
There was a problem hiding this comment.
on_conflict_suffix_sql? When I see "postfix" I think of a mail server.
tests/bulk_create/tests.py
Outdated
tests/bulk_create/tests.py
Outdated
There was a problem hiding this comment.
Add trailing comma please.
Include a trailing comma in cases like this so that if more items are added later, this line doesn't have to be modified again.
tests/bulk_create/tests.py
Outdated
There was a problem hiding this comment.
assertRaisesMessage() (this test is broken) as it doesn't pass on_conflict='ignore'.
django/db/models/query.py
Outdated
There was a problem hiding this comment.
I don't see a strong argument for accepting case-insensitively.
|
I think we should opt for a
|
|
I like that idea, I'll try and implement ASAP. |
|
I've changed |
|
buildbot, test on oracle. |
Ticket
Not sure about the API for this one, passing in the string 'ignore' seemed good as a first stab.
It's a bit tricky to implement, as some backends (mysql, sqlite) need to add a statement or two after the
INSERTstatement, but Postgres needs to add it after theVALUESbut before theRETURNING.I hope this is the right place to implement this. I was going to add a custom per-backend
SQLInsertCompilerthat handles this, but it seemed overkill.