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

[Bug]: Initialising `IList<>` in a `RealmObject` breaks nested lookups

      What happened?

      In conforming to c# 9 nullability, realm models using one-to-many relationships need a value assigned to their get-only list properties to make the compiler happy. My initial approach was to initialise these with a new list:

      Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
          public class RealmBeatmapSet : RealmObject
          {
              public Guid ID { get; set; } = Guid.NewGuid();
      
              public IList<RealmBeatmap> Beatmaps { get; } = new List<RealmBeatmap>();
          }
      

      As it turns out, doing this means even though storing a newly created model works as expected, retrieving an existing object from a realm instance will never show any relations. The fix is easy enough - suppressing null and leaving it to the underlying realm initialisation to make the empty lists works as expected:

      Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
          public class RealmBeatmapSet : RealmObject
          {
              public Guid ID { get; set; } = Guid.NewGuid();
      
              public IList<RealmBeatmap> Beatmaps { get; } = null!;
          }
      

      But this does feel like an easy slip-up to make as a user, and there is no errors or warning as to what is going on.

      Repro steps

      • Initialise an {{IList<T> x {get;}

        }} with a construction-time value

      • Attempt to access a nested object via this relation

      Version

      10.5.0

      What SDK flavour are you using?

      Local Database only

      What type of application is this?

      Console/Server

      Client OS and version

      macOS 12

      Code snippets

      No response

      Stacktrace of the exception/crash you're getting

      No response

      Relevant log output

      No response

            Assignee:
            Unassigned Unassigned
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: