Pnpjs: Batch checkout - update - checkin not executed in specified order

Created on 27 May 2019  路  4Comments  路  Source: pnp/pnpjs

Category

  • [ ] Enhancement
  • [x] Bug
  • [ ] Question
  • [ ] Documentation gap/issue

Version

Please specify what version of the library you are using: [ 1.3.2 ]

Please specify what version(s) of SharePoint you are targeting: [ SharePoint Online ]

Expected / Desired Behavior / Question

In a single batch operation, I specify to checkout a file, edit the associated listitem and check the file in again, in that order, using the following code:

let updateBatch = sp.createBatch();
var batchListItem = sp.web.lists.getById(listId).items.getById(itemId.ID);
batchListItem.file.inBatch(updateBatch).checkout().then(() => console.log("Checked out"));
batchListItem.inBatch(updateBatch).update(data).then(() => console.log("Item updated"));
batchListItem.file.inBatch(updateBatch).checkin("", CheckinType.Major).then(() => console.log("Checked in again"));
await updateBatch.execute();

Observed Behavior

The batch request that is created, puts the checkout and checkin actions first, and then updates the item, resulting in an error, because the file is not checked out.

Steps to Reproduce

  1. Create a batch
  2. Add a checkout action of the file to the batch
  3. Add an update action of the file to the batch
  4. Add a checkin function of the file to the batch
  5. Execute the batch
  6. observe that the execute batch request has the following order:
    a. Checkout
    b. Checkin
    c. Update

Here below a slightly stripped down version of the generated request payload:

--batch_7...
Content-Type: multipart/mixed; boundary="changeset_9..."

--changeset_9...
Content-Type: application/http
Content-Transfer-Encoding: binary

POST https://demotenant.sharepoint.com/sites/demosite/_api/web/lists('<listid>')/items(1)/file/checkout HTTP/1.1

--changeset_9...
Content-Type: application/http
Content-Transfer-Encoding: binary

POST https://demotenant.sharepoint.com/sites/demosite/_api/web/lists('<listid>')/items(1)/file/checkin(comment='',checkintype=1) HTTP/1.1

--changeset_9...
Content-Type: application/http
Content-Transfer-Encoding: binary

MERGE https://demotenant.sharepoint.com/sites/demosite/_api/web/lists('<listid>')/items(1) HTTP/1.1
accept: application/json
content-type: application/json;odata=verbose;charset=utf-8
if-match: *
x-clientservice-clienttag: PnPCoreJS:@pnp-1.3.2

{"__metadata":{"type":"SP.Data.PagesItem"},"field":"value"}

--changeset_9...--

--batch_7...--
code fixed bug

Most helpful comment

I bet you all thought I forgot about this :). I think I have this sorted out now. Need to do some more testing and code cleanup as I had to make some changes within the pipeline which always scares me - BUT I think I finally have ordering fully sorted out.

All 4 comments

Hi @bjdekker, thanks! Looks like a bug. We should have to take a look at this case.

I haven't taken the time to really look into this yet, but I suspect I know why it is happening within the library. We have to wait for the update operation to pre-flight some info (the list item type) so in timeline that operation gets added after the others. Agree a bug, but will I think be a hard one to address quickly.

Thanks for the replies, knowing this, it isn't that hard to put these actions in two separate, sequential batches as a work around

I bet you all thought I forgot about this :). I think I have this sorted out now. Need to do some more testing and code cleanup as I had to make some changes within the pipeline which always scares me - BUT I think I finally have ordering fully sorted out.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

KieranDaviesV picture KieranDaviesV  路  3Comments

SpliceVW picture SpliceVW  路  3Comments

simonagren picture simonagren  路  3Comments

simkessy picture simkessy  路  3Comments

AJIXuMuK picture AJIXuMuK  路  3Comments