Skip to content

Cohort sync fails when fetching paginated Microsoft Graph group members - $skiptoken appended to $select parameter #3138

@HashTagGlitch

Description

@HashTagGlitch

Hello team,

We are experiencing an issue with the Moodle Microsoft 365 integration plugin, specifically with the scheduled task:

local_o365\task\cohortsync

Moodle : 5.2
Plugin : 5.1.1
Php : 8.3.30

The task works correctly when syncing a manually created Microsoft Entra ID group with a small number of users.

However, when using dynamic Microsoft Entra ID groups mapped to Moodle cohorts, the task fails while fetching group members.

The groups and Teams cache update works correctly:

Fetched 1716 groups from Microsoft Graph API.
Fetched 497 teams from Microsoft Graph API.
Found 4 mappings.

The issue occurs during member retrieval for dynamic groups:

Error fetching group members for group ID 169a9a55-f811-4298-a43b-858544b9c525:
Error in API call: Parsing OData Select and Expand failed:
Term 'id?$skiptoken=RFNwdAoAAQ...' is not valid in a $select or $expand expression.

A second dynamic group fails with the same type of error:

Error fetching group members for group ID 8e60596b-b87e-41be-a975-617b60335cea:
Error in API call: Parsing OData Select and Expand failed:
Term 'id?$skiptoken=RFNwdAoAAQ...' is not valid in a $select or $expand expression.

It looks like the plugin may be incorrectly appending the Microsoft Graph pagination parameter $skiptoken to the $select parameter, resulting in something similar to:

$select=id?$skiptoken=...

Instead of handling $skiptoken as a separate query parameter or following the @odata.nextLink URL returned by Microsoft Graph.

This does not look like a permissions issue because:

  • Groups are fetched successfully from Microsoft Graph.
  • Cohort mappings are detected correctly.
  • Manual Entra ID groups sync successfully.
  • The error is an OData parsing error, not a 403 or access denied error.

Expected behavior:
The cohort sync task should correctly handle Microsoft Graph pagination when fetching members of dynamic Microsoft Entra ID groups.

Actual behavior:
The task fails for dynamic groups with an OData parsing error related to $select and $skiptoken.

Could you please confirm whether this is a known issue in the Graph pagination handling for cohort sync?

**** LOGS ****
Execute scheduled task: Cohort sync (local_o365\task\cohortsync)
... started 09:39:35. Current memory use 14.6 MB.
... Groups cache was updated recently. Skipping update. Next update in 22 seconds.
... Groups cache update skipped (rate limit). Proceeding with existing cache.
... Start processing cohort mappings.
...... Found 1716 groups.
...... Found 4 mappings.
......... Processing mapping for group ID cca149ef-e1e7-48e8-9fe8-f9aa2a177fe8 and cohort ID 2.
......... Processing mapping for group ID 169a9a55-f811-4298-a43b-858544b9c525 and cohort ID 4.
...... Error fetching group members for group ID 169a9a55-f811-4298-a43b-858544b9c525: Error in API call: Parsing OData Select and Expand failed: Term 'id?$skiptoken=RFNwdAoAAQAAAAAAAAAAFAAAAG01eFwtqr5DrwJdDbKaeQABAAAAAAAAAAAAAAAAAAAXMS4yLjg0MC4xMTM1NTYuMS40LjIzMzEGAAAAAVWamhYR-JhCpDuFhUS5xSUBATf2QzWPM39HllF-XeN3VZYB5QAAAAEBAAAA' is not valid in a $select or $expand expression.
......... Processing mapping for group ID 8e60596b-b87e-41be-a975-617b60335cea and cohort ID 7.
...... Error fetching group members for group ID 8e60596b-b87e-41be-a975-617b60335cea: Error in API call: Parsing OData Select and Expand failed: Term 'id?$skiptoken=RFNwdAoAAQAAAAAAAAAAFAAAAJ-ZSsqepgFHvrqYctJQA_sBAAAAAAAAAAAAAAAAAAAXMS4yLjg0MC4xMTM1NTYuMS40LjIzMzEGAAAAAWtZYI5-uL5BqXVhe2AzXOoBAZtzT5nCPTFPhX-lmbmb4HwB5QAAAAEBAAAA' is not valid in a $select or $expand expression.
......... Processing mapping for group ID 0a8b7a78-413c-4d02-9fcb-4b4c389dc709 and cohort ID 9.
...... Error fetching group members for group ID 0a8b7a78-413c-4d02-9fcb-4b4c389dc709: Error in API call: Parsing OData Select and Expand failed: Term 'id?$skiptoken=RFNwdAoAAQAAAAAAAAAAFAAAAN87XktqYaBAuQBZIuJ7L3ABAAAAAAAAAAAAAAAAAAAXMS4yLjg0MC4xMTM1NTYuMS40LjIzMzEGAAAAAXh6iwo8QQJNn8tLTDidxwkBATY0_Dl-O75Cq406M6Rn6QYB5QAAAAEBAAAA' is not valid in a $select or $expand expression.
... used 9 dbqueries
... used 2.2742741107941 seconds
... used 25.6 MB peak memory
Scheduled task complete: Cohort sync (local_o365\task\cohortsync)

***** END *****

Thank you.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions