microsoftgraph / microsoftgraph/msgraph-sdk-go

Cannot get nil value from BackingStore with delta query when a property value was changed to nil (empty)

Open
#725 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
335
Forks
43
Avg merge
15h 19m
Merged PRs (30d)
3

Description

I am trying to implement the delta query to track user changes.

For example, I changed First name and Last name to empty on https://entra.microsoft.com/ .

スクリーンショット 2024-06-06 14 21 58

I got the below response. You can see givenName and surname are detected as null values.

{
  "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users",
  "@odata.deltaLink": "https://graph.microsoft.com/v1.0/users/delta()?$deltatoken=dqOf4D0FeifmTE8LZ08sKG_0pMPP7gZ...",
  "value": [
    {
      "givenName": null,
      "surname": null,
      "id": "a8d67d70-f83b-453d-9666-1f280a609bf6"
    }
  ]
}

But, I cannot know whether the givenName and surname were changed to null since the Enumerate() or EnumerateKeysForValuesChangedToNil() methods don't return the values (nil).

var user models.Userable
...
b := user.GetBackingStore()
fmt.Println(b.GetInitializationCompleted())
fmt.Println(b.GetReturnOnlyChangedValues())
for i, v := range b.EnumerateKeysForValuesChangedToNil() {
	fmt.Printf(" - %v, %+v\n", i, v)
}
for k, v := range b.Enumerate() {
	fmt.Printf(" - %s, %+v\n", k, v)
}
- additionalData, map[]
- odataType, 0x140005803b0
- id, 0x14000580320

Another sample code to confirm the user data.

json, _ := serialization.SerializeToJson(user)
fmt.Println(string(json))

Also, the user data doesn't have both givenName and surname properties.

{"id":"a8d67d70-f83b-453d-9666-1f280a609bf6","@odata.type":"#microsoft.graph.user"}

In my debugging, InMemoryBackingStore doesn't handle a nil value in User.GetFieldDeserializers() method.

res["surname"] = func(n i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode) error {
	val, err := n.GetStringValue()
	if err != nil {
		return err
	}
	if val != nil {
		m.SetSurname(val)
	}
	return nil
}
func (m *User) SetSurname(value *string) {
	err := m.GetBackingStore().Set("surname", value)
	if err != nil {
		panic(err)
	}
}

Could you tell me how do I check both givenName and surname properties were changed to nil via msgraph-sdk-go API?

Reference

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with User.GetFieldDeserializers and InMemoryBackingStore, then reproduce the delta response where givenName and surname are null. Trace how the deserializer and backing store handle those values; done means the API lets callers distinguish properties changed to nil, with the behavior checked against the sample delta response.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.