Skip to content

Commit

Permalink
Work around bulk_create consistency issues
Browse files Browse the repository at this point in the history
 bulk_create ends up causing pk consistency issues when doing an update,
 even though we did a and the PK is clear. The .save() on each shockingly
 works. I'm switching this until this is entirely understood.
  • Loading branch information
paultag committed Feb 27, 2015
1 parent adf37df commit 2b86bae
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion opencivicdata/management/commands/loaddivisions.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ def load_divisions(country):
# delete old ids and add new ones all at once
with transaction.atomic():
Division.objects.filter(country=country).delete()
Division.objects.bulk_create(objects, batch_size=10000)
for object_ in objects:
object_.save()
# Division.objects.bulk_create(objects, batch_size=10000)
# XXX: The above line (bulk_create) ends up causing pk consistency
# issues when doing an update, even though we did a delete
# and the PK is clear. The .save() on each shockingly
# works. I'm switching this until this is entirely
# understood.
print(len(objects), 'divisions created')


Expand Down

1 comment on commit 2b86bae

@paultag
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The speed dent here is noticable, but not insane -- it's not run all that often, I think we have to take this hit.

Please sign in to comment.