Uploaded image for project: 'Realm .NET SDK'
  1. Realm .NET SDK
  2. RNET-957

SubscribeForNotifications not called with initial "changes" value null after subscription

    • Type: Icon: Task Task
    • Resolution: Cannot Reproduce
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None

      What happened?

      From the doc of SubscribeForNotifications: https://www.mongodb.com/docs/realm/sdk/dotnet/react-to-changes/

      > Realm emits an initial notification when a subscription is added. After the initial notification, Realm delivers notifications asynchronously whenever a write transaction adds, modifies, or removes objects in the collection.

      It looks like the doc is misleading.

      The handler is never called after subscribing ?

      Repro steps

      I have some code like this:

         var db = Realm.GetInstance(new InMemoryConfiguration("unittests"));
         //...
        disposables.Add(items.SubscribeForNotifications((dbItems, changes, error) => 
      { 
         //code in handler...
      });
      

      Then some code like this in a unit test:

            // SubscribeForNotifications never called before
           await db.RefreshAsync(); //Force realm to refresh and call subscriptions when running on background thread
            // SubscribeForNotifications never called after
      

      "code in handler" is never executed after adding the subscription.

      If a property of one "items" is changed, the handler is called the 1st time with changes=null (as expected for a 1st time). But this 1st time is called way too late.

      So that means the doc is misleading.

      The handler is never called after subscribing ?

      Version

      10.21.0

      What Atlas Services are you using?

      Local Database only

      What type of application is this?

      Console/Server

      Client OS and version

      xunit unit test on .net7

      Code snippets

      No response

      Stacktrace of the exception/crash you're getting

      No response

      Relevant log output

      No response

            Assignee:
            nikola.irinchev@mongodb.com Nikola Irinchev
            Reporter:
            unitosyncbot Unito Sync Bot
            AD SDK Team 2
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: