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

Calling UpdateOverwriteVersionAsync() on List Item Fields Results in Error: "Guid should contain 32 digits with 4 dashes" #1213

Closed
1 task done
adamfisher opened this issue Jun 21, 2023 · 1 comment
Assignees
Labels
area: model 📐 Related to the core SDK models bug Something isn't working

Comments

@adamfisher
Copy link

adamfisher commented Jun 21, 2023

Category

  • Bug

Describe the bug

When you call listItem.UpdateOverwriteVersionAsync() it hard-codes an empty string for the list ID that gets passed into the UpdateListItemRequest object here:

Name = $"121a659f-e03e-2000-4281-1212829d67dd|740c6a0b-85e2-48a0-a494-e0f1759d4aa7:site:{SiteId}:web:{WebId}:list:{ListId}:item:{ItemId},1"

The ListId property gets updated here for the request:

internal async Task PrepareUpdateCall(UpdateListItemRequest request)
{
string listId = "";
if (this.Parent is IFile file)
{
// When it's a file then we need to resolve the {Parent.Id} token manually as otherwise this
// will point to the File id while we need to list Id here
await file.EnsurePropertiesAsync(p => p.ListId).ConfigureAwait(false);
listId = file.ListId.ToString();
}
if (this.Parent.Parent is IList)
{
listId = (this.Parent.Parent as IList).Id.ToString();
}
request.ListId = listId;
List<CSOMItemField> fieldsToUpdate = GetFieldsToUpdate();
request.FieldsToUpdate.AddRange(fieldsToUpdate);
}

Since I am trying to iterate over files and folders it results in no ListId getting populated because I a folder is also a valid list item and results in the "Guid should contain 32 digits with 4 dashes" error message.

Steps to reproduce

I have some code like this:

List<IListItem> items = await targetFolder.GetChildFilesAndFoldersAsync(); // Get some list items (folders AND files)

foreach (var item in items)
{
	var isFolder = await item.IsFolderAsync();
	var listItem = isFolder ? item.Folder.ListItemAllFields : item.File.ListItemAllFields;

	foreach (var columnValue in columnValues)
	{
		listItem[columnValue.FieldInternalName] = columnValue.DefaultValue;
	}

	await listItem.UpdateOverwriteVersionAsync(); // THIS FAILS
}

Produces this error:

crit: Microsoft.Extensions.Hosting.Internal.Host[10]
      The HostOptions.BackgroundServiceExceptionBehavior is configured to StopHost. A BackgroundService has thrown an unhandled exception, and the IHost instance is stopping. To avoid this behavior, configure this to Ignore; however the BackgroundService will not be restarted.
      HttpResponseCode: 200
      Message: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
      ClientRequestId: 1c15bfa0-f06b-3000-c192-b9848adc2223
      ErrorTypeName: "System.FormatException"

      PnP.Core.CsomServiceException: CSOM service exception
         at PnP.Core.Services.BatchClient.ProcessCsomBatchResponse(CsomBatch csomBatch, String batchResponse, HttpStatusCode statusCode)
         at PnP.Core.Services.BatchClient.ExecuteCsomBatchAsync(Batch batch)
         at PnP.Core.Services.BatchClient.ExecuteBatch(Batch batch)
         at PnP.Core.Model.BaseDataModel`1.RequestAsync(ApiCall apiCall, HttpMethod method, String operationName)
         at PnP.Core.Model.BaseDataModel`1.RawRequestAsync(ApiCall apiCall, HttpMethod method, String operationName)
         at PnP.Core.Model.SharePoint.ListItem.UpdateOverwriteVersionAsync()

The resulting query body that gets generated for the request looks like this:

<Request AddExpandoFieldTypeSuffix="true" SchemaVersion="15.0.0.0" LibraryVersion="16.0.0.0" ApplicationName="pnp core sdk"
	xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009">
	<Actions>
		<Method Name="SetFieldValue" Id="4" ObjectPathId="1">
			<Parameters>
				<Parameter Type="String">Project_Number</Parameter>
				<Parameter Type="String">ABC-1234</Parameter>
			</Parameters>
		</Method>
		<Method Name="SetFieldValue" Id="5" ObjectPathId="1">
			<Parameters>
				<Parameter Type="String">Project_Description</Parameter>
				<Parameter Type="String">Test Project</Parameter>
			</Parameters>
		</Method>
		<Method Name="UpdateOverwriteVersion" Id="10" ObjectPathId="1"></Method>
	</Actions>
	<ObjectPaths>
		<Identity Id="1" Name="93fce522-9389-4e91-8c94-23840e8bdbad|bc0d68ff-a6d1-4694-8c50-752ae6c94543:site:5a501e7a-3535-4f81-a678-c8ff32291200:web:e9798d37-7a2f-4645-8f77-4d08467e3204:list::item:8635,1" />
	</ObjectPaths>
</Request>

I verified my ListItem and the folder both had UniqueId's present but they are not getting populated in this request. list::item:8635,1" /> should have a GUID right after list:<GUID_HERE> at the end of that request.

Expected behavior

The UpdateListItemRequest object should be populated with the correct ListId so the request succeeds instead of failing because no ListId was present in the request.

Environment details (development & target environment)

  • SDK version: 16.1.23710.12000
  • OS: Windows 10
  • SDK used in: Console App
  • Framework: .NET Core v3.x
  • Browser(s): Chrome v79
  • Tooling: Visual Studio 2022
@jansenbe jansenbe self-assigned this Jun 22, 2023
@jansenbe jansenbe added bug Something isn't working area: model 📐 Related to the core SDK models labels Jun 22, 2023
jansenbe added a commit that referenced this issue Jun 22, 2023
…emAllFields` when that was loaded from a `IFolder` resulted in error: "Guid should contain 32 digits with 4 dashes" #1213
@jansenbe
Copy link
Contributor

Thanks for debugging this @adamfisher , I've pushed a fix which will be included in the next nightly. Closing this issue, please re-open when you still have problems with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: model 📐 Related to the core SDK models bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants