microsoftgraph / msgraph-sdk-go

Microsoft Graph SDK for Go
https://docs.microsoft.com/en-us/graph/sdks/sdks-overview
MIT License
214 stars 32 forks source link

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

Open t2y opened 1 month ago

t2y commented 1 month ago

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