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

User Patch request fails if 'displayName' is not present #2561

Closed
bolt-io opened this issue Jun 25, 2024 · 6 comments
Closed

User Patch request fails if 'displayName' is not present #2561

bolt-io opened this issue Jun 25, 2024 · 6 comments
Labels

Comments

@bolt-io
Copy link

bolt-io commented Jun 25, 2024

Describe the bug

I am trying to update a user's surname but forced to provide a value for displayName for any patch requests. This is not a required field from the Microsoft Graph API.

Response error:

  Message: 
Microsoft.Graph.Models.ODataErrors.ODataError : A value is required for property 'displayName' of resource 'User'.

  Stack Trace: 
HttpClientRequestAdapter.ThrowIfFailedResponse(HttpResponseMessage response, Dictionary`2 errorMapping, Activity activityForAttributes, CancellationToken cancellationToken)
HttpClientRequestAdapter.SendAsync[ModelType](RequestInformation requestInfo, ParsableFactory`1 factory, Dictionary`2 errorMapping, CancellationToken cancellationToken)
HttpClientRequestAdapter.SendAsync[ModelType](RequestInformation requestInfo, ParsableFactory`1 factory, Dictionary`2 errorMapping, CancellationToken cancellationToken)
UserItemRequestBuilder.PatchAsync(User body, Action`1 requestConfiguration, CancellationToken cancellationToken)
GraphUserRepository.UpdateUserAsync[TInput](String id, TInput user) line 126
GraphUserRepositoryTests.UpdateUserAsync_WhenUserExists_ReturnsTrue(String userId) line 173
GenericAdapter`1.BlockUntilCompleted()
NoMessagePumpStrategy.WaitForCompletion(AwaitAdapter awaiter)
AsyncToSyncAdapter.Await[TResult](Func`1 invoke)
AsyncToSyncAdapter.Await(Func`1 invoke)
TestMethodCommand.RunTestMethod(TestExecutionContext context)
TestMethodCommand.Execute(TestExecutionContext context)
BeforeTestCommand.Execute(TestExecutionContext context)
<>c__DisplayClass3_0.<PerformWork>b__0()
<>c__DisplayClass1_0`1.<DoIsolated>b__0(Object _)
ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
ContextUtils.DoIsolated(ContextCallback callback, Object state)
ContextUtils.DoIsolated[T](Func`1 func)
SimpleWorkItem.PerformWork()

Expected behavior

The user is updated without the forced requirement of displayName being provided.

How to reproduce

Run the following code snippet against the Graph Service Client with a valid user ID

User updatedUser = new() { GivenName = "someValue" };

await _graphServiceClient.Users["{userId}"].PatchAsync(updatedUser).ConfigureAwait(false);

SDK Version

5.56.0

Latest version known to work for scenario above?

No response

Known Workarounds

No response

Debug output

Click to expand log ```
</details>


### Configuration

_No response_

### Other information

_No response_
@bolt-io bolt-io added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Jun 25, 2024
@andrueastman
Copy link
Member

Thanks for raising this @bolt-io.

As this is an issue related to the functionality of the API and this repo is mainly intended for SDK related issues, any chance you can post the question at the link below to get feedback from the relevant API owners?

https://aka.ms/askGraph

@andrueastman andrueastman added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close and removed status:waiting-for-triage An issue that is yet to be reviewed or assigned labels Jun 25, 2024
@bolt-io
Copy link
Author

bolt-io commented Jun 25, 2024

@andrueastman it would look to me like the issue is somewhere in the SDK as running directly against the Graph API results in a success response (see below)

image

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 and removed status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close labels Jun 25, 2024
@MartinM85
Copy link
Contributor

If the request body (in Graph Explorer) is

{
    "givenName": "Dee",
    "displayName": null
}

It returns the exception mentioned above: A value is required for property 'displayName' of resource 'User'.

@andrueastman
Copy link
Member

@bolt-io Any chance you can confirm the payload sent by the SDK using fiddler or running the code below from your end?

            User updatedUser = new() { GivenName = "someValue" };
            var stringValue = await KiotaJsonSerializer.SerializeAsStringAsync(updatedUser);

The json string produced from my end does not contain the displayName property set to null when we run this.

@andrueastman andrueastman added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close and removed Needs: Attention 👋 labels Jun 26, 2024
@bolt-io
Copy link
Author

bolt-io commented Jun 26, 2024

Thanks @MartinM85 and @andrueastman.

@bolt-io Any chance you can confirm the payload sent by the SDK using fiddler or running the code below from your end?

            User updatedUser = new() { GivenName = "someValue" };
            var stringValue = await KiotaJsonSerializer.SerializeAsStringAsync(updatedUser);

The json string produced from my end does not contain the displayName property set to null when we run this.

Correct. The JSON string payload only contains Givenname and OData.Type. This is what I would have expected the Graph SDK to send.

However, I have found the reason it was not serializing correctly.
Our method takes in a generic which is deserialized into a User object (shared project, we want it to be extendable without forcing dependency on Graph Models in business layer).

            var graphuser = new User() { GivenName = "someValue" };
            User updatedUser = JsonSerializer.Deserialize<User>(JsonSerializer.Serialize(graphuser));
            var stringValue = await KiotaJsonSerializer.SerializeAsStringAsync(updatedUser);

image

Turns out if you do any pre-serialization on the object, even if the KiotaJsonSerializer gets a User object, it will serialize with null values as above...

This can be negated by serialising with options new JsonSerializerOptions() { DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull} and KiotaJsonSerializer will return as expected.

Thanks folks for the help, issue was between keyboard and chair (and some dodgy code) 😅

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 and removed status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close labels Jun 26, 2024
@andrueastman
Copy link
Member

Thanks for confirming @bolt-io. Closing this one for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants