Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #30138 -- Changed QuerySet.bulk_create() to set pk of created objects when ignore_conflicts=True. #12233

Closed
wants to merge 1 commit into from

Conversation

hramezani
Copy link
Member

@hramezani hramezani commented Dec 20, 2019

Ticket 30138
Continue to The PR

@charettes
Copy link
Member

I'm not sure I understand how this will work.

Say that you have the following objects existing

TwoFields.objects.create(f1=1, f2=1)
TwoFields.objects.create(f1=3, f2=3)

And then you do a

TwoFields.objects.bulk_create([
    TwoFields(f1=1, f2=1),
    TwoFields(f1=2, f2=2),
    TwoFields(f1=3, f2=3),
], ignore_conflicts=True)

From my understanding the database will not return any conflicting row ids which means you'll have a mismatch between the number of returned ids and the number of objects passed to bulk_create and won't be able to assign the proper values.

@hramezani
Copy link
Member Author

hramezani commented Dec 25, 2019

@charettes Yes, you are right the database will not return any conflicting row ids.

Based on the Ticket and last PR it seems we need to add newly created item id to the results. Is there any way to match the number of returned ids and the number of objects passed to bulk_create?
If something else is in your mind please share it with me. I can work on it.

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.

2 participants