Uploaded image for project: 'Realm JavaScript SDK'
  1. Realm JavaScript SDK
  2. RJS-1934

Aggregation functions return `undefined` when they should return `null`

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None

      How frequently does the bug occur?

      Seen once

      Description

      Our types declare that the min, max and sum can return null:

      Unable to find source-code formatter for language: typescript. 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
      min(property?: string): number | Date | null;
      max(property?: string): number | Date | null;
      sum(property?: string): number | null;
      avg(property?: string): number;
      

      But the implementation shows that min, max and avg actually return undefined when there are no objects in the collection:

      Unable to find source-code formatter for language: typescript. 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
      const realm = new Realm({
        schema: [{
          name: "Item",
          properties: { value: "int" }
        }],
      });
      realm.objects("Item").min("value"); // returns `undefined`
      realm.objects("Item").max("value"); // returns `undefined`
      realm.objects("Item").avg("value"); // returns `undefined`
      realm.objects("Item").sum("value"); // returns `0`
      

      We are actually testing, to ensure this behaviour ☝️
      https://github.com/realm/realm-js/blob/master/tests/js/list-tests.js#L1389-L1392

      Stacktrace & log output

      No response

      Can you reproduce the bug?

      Yes, always

      Reproduction Steps

      No response

      Version

      10.21.1

      What SDK flavour are you using?

      Local Database only

      Are you using encryption?

      No, not using encryption

      Platform OS and version(s)

      Tested on Node.js

      Build environment

      No response

      Cocoapods version

      No response

            Assignee:
            Unassigned Unassigned
            Reporter:
            kraen.hansen@mongodb.com Kræn Hansen
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: