Skip to content

Fixed #28668 -- Support ignoring conflicts with bulk_create()#9192

Merged
timgraham merged 1 commit intodjango:masterfrom
orf:28668-on-conflict
Aug 3, 2018
Merged

Fixed #28668 -- Support ignoring conflicts with bulk_create()#9192
timgraham merged 1 commit intodjango:masterfrom
orf:28668-on-conflict

Conversation

@orf
Copy link
Copy Markdown
Contributor

@orf orf commented Oct 2, 2017

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 INSERT statement, but Postgres needs to add it after the VALUES but before the RETURNING.

I hope this is the right place to implement this. I was going to add a custom per-backend SQLInsertCompiler that handles this, but it seemed overkill.

@orf orf changed the title Closes #28668 -- Support ignoring conflicts with bulk_create() Fixed #28668 -- Support ignoring conflicts with bulk_create() Oct 3, 2017
_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')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NotSupportedError

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed 👍

Copy link
Copy Markdown
Member

@timgraham timgraham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use is_postgresql_9_5

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on_conflict_suffix_sql? When I see "postfix" I think of a mail server.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use single quotes please.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertRaisesMessage() (this test is broken) as it doesn't pass on_conflict='ignore'.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a strong argument for accepting case-insensitively.

@charettes
Copy link
Copy Markdown
Member

charettes commented Jul 31, 2018

I think we should opt for a ignore_conflicts=False boolean argument instead of using a string constant just like we did with select_for_update(nowait=False, skip_locked=False) instead of select_for_update(if_locked=('skip' | 'wait' | 'error')) in the name of consistency.

ignore_conflicts is also more implementation agnostic IMHO while on_conflict is really standard SQL bound.

@orf
Copy link
Copy Markdown
Contributor Author

orf commented Jul 31, 2018

I like that idea, I'll try and implement ASAP.

@orf
Copy link
Copy Markdown
Contributor Author

orf commented Jul 31, 2018

I've changed on_conflict to ignore_conflicts everywhere, including the DB feature boolean.

@orf
Copy link
Copy Markdown
Contributor Author

orf commented Jul 31, 2018

buildbot, test on oracle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants