microsoftgraph / msgraph-sdk-serviceissues

Tracks service issues for follow up.
5 stars 0 forks source link

Case sensitivity in the batch endpoint causes error: Error: Request Id <id> has to be unique in a batch #63

Open supersime opened 3 years ago

supersime commented 3 years ago

We are sending POST requests to the /$batch endpoint of the graph to retrieve multiple calendar events. A request looks like this:

{
        "requests": [
            {
                "url": "/me/events/AAMkADU2ZmU2MTE3LTYxYWQtNGU0Mi05MmU0LWU1ZWFhNTM2NmM1YgBGAAAAAAAXZ-bpSu6cRoxPjVciIsNcBwDTaXQE7hV-QZy91ycCynXBAAAAAAENAADTaXQE7hV-QZy91ycCynXBAAAF5QtgAAA=?$select=subject,organizer,attendees,start,end",
                "method": "GET",
                "id": "AAMkADU2ZmU2MTE3LTYxYWQtNGU0Mi05MmU0LWU1ZWFhNTM2NmM1YgBGAAAAAAAXZ-bpSu6cRoxPjVciIsNcBwDTaXQE7hV-QZy91ycCynXBAAAAAAENAADTaXQE7hV-QZy91ycCynXBAAAF5QtgAAA="
            },
            {
                "url": "/me/events/AAMkADU2ZmU2MTE3LTYxYWQtNGU0Mi05MmU0LWU1ZWFhNTM2NmM1YgBGAAAAAAAXZ-bpSu6cRoxPjVciIsNcBwDTaXQE7hV-QZy91ycCynXBAAAAAAENAADTaXQE7hV-QZy91ycCynXBAAAF5QtGAAA=?$select=subject,organizer,attendees,start,end",
                "method": "GET",
                "id": "AAMkADU2ZmU2MTE3LTYxYWQtNGU0Mi05MmU0LWU1ZWFhNTM2NmM1YgBGAAAAAAAXZ-bpSu6cRoxPjVciIsNcBwDTaXQE7hV-QZy91ycCynXBAAAAAAENAADTaXQE7hV-QZy91ycCynXBAAAF5QtGAAA="
            }
        ]
    }

Notice that the "url" and "id" in the two events are almost identical... the 5th last character is "g" in the first request, and "G" in the second request. The "id" we pass in, is the id of the outlook calendar event.

The graph sdk responds with the following error:

"error": {
        "message": "Request Id AAMkADU2ZmU2MTE3LTYxYWQtNGU0Mi05MmU0LWU1ZWFhNTM2NmM1YgBGAAAAAAAXZ-bpSu6cRoxPjVciIsNcBwDTaXQE7hV-QZy91ycCynXBAAAAAAENAADTaXQE7hV-QZy91ycCynXBAAAF5QtGAAA= has to be unique in a batch.",
        "name": "Error",
        "stack": "Error: Request Id AAMkADU2ZmU2MTE3LTYxYWQtNGU0Mi05MmU0LWU1ZWFhNTM2NmM1YgBGAAAAAAAXZ-bpSu6cRoxPjVciIsNcBwDTaXQE7hV-QZy91ycCynXBAAAAAAENAADTaXQE7hV-QZy91ycCynXBAAAF5QtGAAA= has to be unique in a batch.\n    at new GraphError (/app/server/node_modules/@microsoft/microsoft-graph-client/lib/src/GraphError.js:31:28)\n    at Function.GraphErrorHandler.constructErrorFromResponse (/app/server/node_modules/@microsoft/microsoft-graph-client/lib/src/GraphErrorHandler.js:61:22)\n    at Function.<anonymous> (/app/server/node_modules/@microsoft/microsoft-graph-client/lib/src/GraphErrorHandler.js:92:48)\n    at step (/app/server/node_modules/tslib/tslib.js:136:27)\n    at Object.next (/app/server/node_modules/tslib/tslib.js:117:57)\n    at /app/server/node_modules/tslib/tslib.js:110:75\n    at new Promise (<anonymous>)\n    at Object.__awaiter (/app/server/node_modules/tslib/tslib.js:106:16)\n    at Function.GraphErrorHandler.getError (/app/server/node_modules/@microsoft/microsoft-graph-client/lib/src/GraphErrorHandler.js:88:24)\n    at GraphRequest.<anonymous> (/app/server/node_modules/@microsoft/microsoft-graph-client/lib/src/GraphRequest.js:305:84)\n    at step (/app/server/node_modules/tslib/tslib.js:136:27)\n    at Object.throw (/app/server/node_modules/tslib/tslib.js:117:57)\n    at rejected (/app/server/node_modules/tslib/tslib.js:108:69)\n    at runMicrotasks (<anonymous>)\n    at processTicksAndRejections (internal/process/task_queues.js:93:5)",
        "code": "BadRequest"
    }

I would have expected the api request to allow this, as they are two separate, unrelated calendar events.

"@microsoft/microsoft-graph-client": "^2.2.1" Running on node v14.15.4

AB#9124

nikithauc commented 3 years ago

@supersime Thank you for reporting this issue!

Can you please provide a request-id and a client-request id for this error?

nikithauc commented 3 years ago

@supersime

The id property functions primarily as a correlation value to associate individual responses with requests. This allows the server to process requests in the batch in the most efficient order.

https://docs.microsoft.com/en-us/graph/json-batching?context=graph%2Fapi%2F1.0&view=graph-rest-1.0

The ids are not the event ids. Can you please trying changing the values of the ids and let me know if that works? https://docs.microsoft.com/en-us/graph/sdks/batch-requests?tabs=typescript

supersime commented 3 years ago

Thanks @nikithauc ... yes I certainly understand the event ids do not need to be the ids... we are, however, using the event ids as the ids because this makes the correlation easier for us (without an interim step to generate a new id just for the batch post).

I have just reproduced as follows:

{
    "requests": [
        {
            "url": "/me/events/AAMkADU2ZmU2MTE3LTYxYWQtNGU0Mi05MmU0LWU1ZWFhNTM2NmM1YgBGAAAAAAAXZ-bpSu6cRoxPjVciIsNcBwDTaXQE7hV-QZy91ycCynXBAAAAAAENAADTaXQE7hV-QZy91ycCynXBAAAF5QtgAAA=?$select=subject,organizer,attendees,start,end",
            "method": "GET",
            "id": "g"
        },
        {
            "url": "/me/events/AAMkADU2ZmU2MTE3LTYxYWQtNGU0Mi05MmU0LWU1ZWFhNTM2NmM1YgBGAAAAAAAXZ-bpSu6cRoxPjVciIsNcBwDTaXQE7hV-QZy91ycCynXBAAAAAAENAADTaXQE7hV-QZy91ycCynXBAAAF5QtGAAA=?$select=subject,organizer,attendees,start,end",
            "method": "GET",
            "id": "G"
        }
    ]
}

and the error response:

{
    "error": {
        "code": "BadRequest",
        "message": "Request Id G has to be unique in a batch.",
        "innerError": {
            "date": "2021-04-27T00:17:07",
            "request-id": "af710e55-1994-4cd8-986c-95c99012113b",
            "client-request-id": "77e36343-5f30-1e6f-37d1-3e74ae1762d5"
        }
    }
}

The issue is only because there are two ids that are identical when you don't consider the case. Essentially it is treating "g" and "G" as the same and therefore a duplicate. But these are not the same.

nikithauc commented 3 years ago

@supersime The Graph API design intends to be case insensitive. The issue you reported highlights a bug and Thank you for reporting it! I am following up on this issue and I will provide an update as and when I learn more about this.

supersime commented 3 years ago

Thanks @nikithauc ... I assume you mean the design intends to be case sensitive? That's great news... I look forward to hearing about its resolution.

petrhollayms commented 2 months ago

Thank you for reporting this issue. This appears to be an issue or limitation with the service APIs. Unfortunately, as the Microsoft Graph SDK team, we do not have ownership of the APIs that are causing you issues. We invite you to create a question about the service API to Microsoft Q&A and tagged with one of the [microsoft-graph-*] tags, that way it will get routed to the appropriate team for them to triage:

https://aka.ms/msgraphsupport or directly https://aka.ms/askgraph

For now, we will close the issue on our side but feel free to open it in the relevant repository if you think the issue is specific to SDK. Please let us know if this helps!

Note: We will close this repository on April 19, 2024.