Skip to content

GetCommentsAsync throws InvalidClientQueryException after upgrading from 1.8.0 to 1.9.0 #1191

@larry-lau

Description

@larry-lau

Category

  • Bug

Describe the bug

After upgrading from 1.8.0 to 1.9.0, GetCommentsAsync throws the following exception:

Exception: HttpResponseCode: 400
Code: Microsoft.SharePoint.Client.InvalidClientQueryException
Message: The expression "web/lists/getbyid(guid'962')/items(962)/getcomments" is not valid.
ClientRequestId: a190b6a0-70da-3000-9ff5-bfeebae0befc
SPClientServiceRequestDuration: 10
X-SharePointHealthScore: 1
X-SP-SERVERSTATE: ReadOnly=0

PnP.Core.SharePointRestServiceException: SharePoint Rest service exception
at PnP.Core.Services.BatchClient.ExecuteSharePointRestInteractiveAsync(Batch batch)
at PnP.Core.Services.BatchClient.ExecuteSharePointRestBatchAsync(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.SharePoint.ListItem.GetCommentsAsync(Expression`1[] selectors)
at PnP.Core.Model.SharePoint.Page.GetCommentsAsync(Expression`1[] selectors)
at PnP.Core.Model.SharePoint.Page.GetComments(Expression`1[] selectors)

This code snippets works in 1.8.0 but no longer works in 1.9.0

var page = context.Web.GetPages(pageName).FirstOrDefault();
var comments = await page.GetCommentsAsync(
                            p => p.Author,
                            p => p.Text,
                            p => p.ReplyCount,
                            p => p.CreatedDate,
                            p => p.Replies);

Steps to reproduce

  1. See code above
  2. Run the above code to get comments in version 1.8.0
  3. Works
  4. Upgrade to 1.9.0 and Run the above code again
  5. See error

Expected behavior

It should return a list of comments like it used to in version 1.8.0

Environment details (development & target environment)

  • SDK version: [1.9.0]
  • OS: [Windows 10]
  • SDK used in: [Console App | Azure Functions]
  • Framework: [.NET 7]
  • Browser(s): [N/A]
  • Tooling: [Visual Studio 2022]
  • Additional details:

Additional context

Looking at the Item API REST expression...It appears it mistakenly uses the numeric item ID of the item to get the list which should use GUID.
"web/lists/getbyid(guid'962')/items(962)/getcomments

There are two issues:

  1. It should use the List ID not the Item ID
  2. Wrong data type, the LIst ID should be GUID not numeric value.

This generated Item expression seem to be invalid in version 1.9.0

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions