question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Implement .bulk_update(...)

See original GitHub issue

The method bulk_update is new in Django 2.2.

Implement it in Django-salesforce.

Notes: A method salesforce.dbapi.driver.RawConnection.sobject_collections_request(...) was written for this purpose. The implementation in Django is completely different. Therefore we will not use any code from a Django method and easily backport it for Salesforce backend also to an old Django.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
hynekcercommented, Jan 30, 2020

Thanks for your interest and the offer. I can write some useful details: I think that the driver part with cursor.db.connection.sobject_collections_request('PATCH', records) has been worked correctly since v0.8.1. We should (and you can start it until you can) monkey paste the method bulk_update (source code) to salesforce.backend.query.SalesforceQuerySet. You see there a similar bulk_create The problematic useless part in the original bulk_update is with CASE … WHEN … is here. Therefore we will not call it by super() at all and useful parts like checks should be copied to our method.

Also tests are useful also for understanding the SFDC API. I have test only for bulk_create in tests.test_mock.test_data.test_create() (I use “mocked” simplified recorded real responses of new SFDC API features that were documented with no or little examples because sometimes later after an new SFDC version it is easier for maintenance (if a problem is not found while in the release preview window). I think that e. g. error reporting with or without “allOrNone” has been changed in some /services/data/{API_VERSION}/composite/sobjects and the change can not be verified because if even doesn’t depend on API_VERSION parameter but only the release.)

It is still not clear what is the preferred way for django-salesforce users with handling of allOrNone parameter - that is similar to turn on transactions instead of autocommit. The batch size is 200 records for Salesforce. It is not possible to create a bigger “pseudo-transaction” than 200 records. It was also problematic, how to report succeeded / failed / cancelled updates to the end user if it is a mix (for records > 200). Maybe add a parameter all_or_none to the method. Some people use SalesforceModels on sqlite for simple fast tests.

So the minimal implementation is not too complicated, but there are many details and the final solution will require a discussion. Please can you start some work?

0reactions
hynekcercommented, Jun 4, 2021

The queryset methods .bulk_create(...), .update(...), .delete(...) can be run with option all_or_none by the method .sf(all_or_none=True) added somewhere before them in the queryset chain of a SalesforceModel.

Contact.objects.sf(all_or_none=True).bulk_create(...)

That works also with normal databases, where the option the option all_or_none is ignored. If a method .sf() should exist in querysets for non-salesforce databases (e.g in tests) then the SalesforceModel should be imported from module salesforce.models_extend. That will be maybe a normal SalesforceModel, but currently it must be enabled explicitly by user that want it to can send a feedback continue with the old class until the new become generally acceptable.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bulk Update in Bulk Operations
The BulkUpdate method lets you update a large number of entities in your database. // easy to use bulk.DestinationTableName = "Customers"; bulk.
Read more >
Bulk Update in EF Extensions (EFE)
The EF BulkUpdate extension method let you update a large number of entities in your database. // Easy to use context.BulkUpdate(customers); // Easy...
Read more >
BulkUpdate - RepoDB
BulkUpdate. This method is used to update all the rows from the client application into the database by bulk. It is only supporting...
Read more >
Performing Bulk Update - Telerik
Performing Bulk Update. The bulk update operation allows you to update data, based on filters expressed as LINQ queries, without loading it in...
Read more >
bulkUpdate in sequelize orm - node.js - Stack Overflow
Use the bulkCreate to bulkUpdate method. bulkCreate([...], { updateOnDuplicate: ["name"] }). updateOnDuplicate is an array of fields that ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found