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

Batch request on different items with same id cause "PnP.Core.ClientException: This model instance was deleted" - Consolidation not precise enough #1581

Open
1 task done
GrubenPete opened this issue Nov 22, 2024 · 0 comments

Comments

@GrubenPete
Copy link

Category

  • Bug

Describe the bug

While requesting same properties for list items with same id of different lists in the same batch request, consolidation marks those items as deleted causing ClientException:

PnP.Core.ClientError
      PnP.Core.ClientException: This model instance was deleted, you can't use it anymore
         at PnP.Core.Model.TransientObject.CheckDeleted()
         at PnP.Core.Model.TransientObject.GetValue[T](String propertyName)
         at PnP.Core.Model.SharePoint.ListItem.get_Id()
         at InvokeStub_ListItem.get_Id(Object, Object, IntPtr*)
         at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
         --- End of inner exception stack trace ---
         at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
         at System.Reflection.PropertyInfo.GetValue(Object obj)
         at PnP.Core.Services.BatchClient.ExecuteBatch(Batch batch)
         at PnP.Core.Services.PnPContext.ExecuteAsync(Batch batch, Boolean throwOnError)

Steps to reproduce

You need 2 Lists each containing an item with the same id (not unique id).

var batch = _pnpContext.NewBatch();

await _pnpContext.Web.Lists.LoadBatchAsync(batch, list => list.Id, list => list.Items.QueryProperties(item => item.Id);

foreach (var list in _pnpContext.Web.Lists.AsRequested()) {
    foreach (var item in list.Items.AsRequested()) {
        await item.LoadBatchAsync(batch, li => li.Id, li => li.UniqueId);
    }
}

resulting both items in same consolidation list:

{Id: 15, UniqueId: '0d00aea2-80ab-4cec-b263-fbe053abff9f'},
{Id: 15, UniqueId: '1d3dc520-9baa-415f-8ef7-4fcd9e27c1be'}

so those items are wrongly merged although they are different items.

Expected behavior

Either document this behavior -> We can not reliable request items of different Lists in the same batch request.
Or use UniqueId as KeyField where possible. BatchClient.cs#L2583

Environment details (development & target environment)

SDK version: 1.14.0
OS: Windows 11
SDK used in: ASP.NET Core Web API
Framework: .Net 8
Tooling: Visual Studio 2022

Additional context

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

No branches or pull requests

1 participant