2

I'm using bulk_create to insert thousand of users once:

new_users_bulk_list.append(User(user_id=user_id, date_of_birth=dob))
    if len(new_users_bulk_list) >= settings.BULK_LIMIT:
        try:
            User.objects.bulk_create(new_users_bulk_list)
            new_users_bulk_list[:] = []
        except Exception as e:
            print("Error: Creating users " + str(e))

and bulk_update to update many records:

user_bulk.append(user_sequence)
        if len(user_bulk) == settings.BULK_LIMIT:
            bulk_update(user_bulk)
            user_bulk[:] = []

If bulk_create or bulk_update fails in creating/updating records, how can I identify these failed records? Is there a way to catch specific failed records ?

Thank you,

Maha
  • 519
  • 2
  • 11
  • 23

1 Answers1

1

I don't think it is possible to do so. This answer may give you some insight.

A far-from-perfect workaround I might suggest: manually split new_users_bulk_list into batches of some size. That may at least give you some degree of control over what's happening and what's failing.

Community
  • 1
  • 1