Skip to content

Conversation

@jvaesteves
Copy link

Overview

At this moment, when making any BatchRequests, the any primitive value in the results that are not strings are not being properly deserialized. That is because the case grouping was not done properly, and it skips all possible returns inside the switch block, falling into the return nil, nil loc. This simple change fixes this by properly collapsing these options into a single case, separate by commas.

Testing

  • To replicate my original scenario, I did find this issue by batching mutiple client.Drives().ByDriveId(driveID).Items().ByDriveItemId(fileID) in a single batch
  • When selecting any non-string values, like size in my case, these values were returned nil
  • With this change, they return with their expected type

You can use the following snippet to replicate this test. If everything goes as expected, it should not panic at all

requestConfig := &msgraph_drives.ItemItemsDriveItemItemRequestBuilderGetRequestConfiguration{
	QueryParameters: &msgraph_drives.ItemItemsDriveItemItemRequestBuilderGetQueryParameters{
		Select: ["size"], // anything else, but this was my main issue
	},
}

driveItemIds := []string{} // just add a driveItemId for any non-empty file in OneDrive/Sharepoint
driveItemIdToStepId := make(map[string]*string, len(driveItemIds))

for _, driveItemId := range driveItemIds {
	reqInfo, err := client.Drives().ByDriveId(driveID).Items().ByDriveItemId(driveItemId).ToGetRequestInformation(ctx, requestConfig)
	if err != nil {
		panic(err)
	}

	step, err := batchCollection.AddBatchRequestStep(*reqInfo)
	if err != nil {
		panic(err)
	}

	driveItemIdToStepId[driveItemId] = step.GetId()
}

batchResponse, err := batchCollection.Send(ctx, client.GetAdapter())
if err != nil {
	panic(err)
}

for _, driveItemId := range driveItemIds {
    stepID := driveItemIdToStepId[driveItemId]
    driveItem, err := msgraphcore.GetBatchResponseById[models.DriveItemable](
        batchResponse, *stepID, models.CreateDriveItemFromDiscriminatorValue,
    )
    if err != nil {
        panic(err)
    }

    if driveItem.GetSize() == nil {
        panic(fmt.Errorf("size is nil for driveItem %s", driveItemId))
    }
}

@jvaesteves jvaesteves requested a review from a team as a code owner November 13, 2025 09:59
@jvaesteves jvaesteves changed the title fix: Collapse primitve type switch options into a single case fix: Fix BatchItem deserialization for non-string primitive values Nov 13, 2025
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

Successfully merging this pull request may close these issues.

1 participant