locked
BUG: GroupBy null key. RRS feed

  • Question

  • This one has caught me out really badly.

    I'm running the 2.0.20823 version of Rx using NuGet packages.

    Consider the following code (run in LinqPad):

    (new int?[] { 1, 2, 3, null, 1, 2 })
        .GroupBy(i => i)
        .Select(g => new KeyValuePair<int?, int>(g.Key, g.Count()))
        .ToArray()
        .Dump();

    Correctly outputs counts of ints (this is a trivial example for simplicity).

    An Rx equivalent:

    (new int?[] { 1, 2, 3, null, 1, 2 }).ToObservable()
        .GroupBy(i => i)
        .SelectMany(async g => new KeyValuePair<int?, int>(g.Key, await g.Count()))
        .ToArray()
        .Dump();

    Throws an ArgumentNullException, for parameter 'key'.  Caused by the GroupBy using a Dictionary internally (and as we all know, or should know) Dictionaries do not accept null as a key...

    I think this is a bug, for the following reasons:

    1. It doesn't demonstrate comparable behaviour with Enumerable.GroupBy - which supports null as a key without issues.
    2. The MSDN documentation for Observable.GroupBy makes no mention of a requirement that the key be non null - http://msdn.microsoft.com/en-us/library/hh229645(v=vs.103).aspx

    Happy to be corrected :)

    I have searched the forums but couldn't find a duplicate - is there somewhere more appropriate to raise this as a bug?


    thargy

    Craig Dean (MCPD)
    Chief Executive
    www.webappuk.com

    Please consider marking this as the answer if you have been genuinely helped!


    • Edited by thargy Friday, October 26, 2012 11:37 AM Made friendlier
    Friday, October 26, 2012 9:28 AM

Answers

  • Thanks for letting us know. This will be fixed in the upcoming update.

    using (Microsoft.Sql.Cloud.DataProgrammability.Rx) { Signature.Emit("Bart De Smet"); }

    • Proposed as answer by Bart De Smet [MSFT] Friday, October 26, 2012 5:48 PM
    • Marked as answer by thargy Friday, October 26, 2012 11:50 PM
    Friday, October 26, 2012 5:48 PM

All replies

  • Thanks for letting us know. This will be fixed in the upcoming update.

    using (Microsoft.Sql.Cloud.DataProgrammability.Rx) { Signature.Emit("Bart De Smet"); }

    • Proposed as answer by Bart De Smet [MSFT] Friday, October 26, 2012 5:48 PM
    • Marked as answer by thargy Friday, October 26, 2012 11:50 PM
    Friday, October 26, 2012 5:48 PM
  • Very, very happy not to get the "it's a feature response" :)

    Can I also respectfully suggest adding a unit test for nulls, it being the most common cause of bugs - and so this has a really good chance of 'reappearing' in future.


    thargy

    Craig Dean (MCPD)
    Chief Executive
    www.webappuk.com

    Please consider marking this as the answer if you have been genuinely helped!

    Friday, October 26, 2012 11:52 PM
  • I can confirm this is now fixed as v.2.0.21030 of the NuGet, however this brought up another minor issue.  I've just spent 10 minutes searching for release notes, bugs db, known issues, etc. for Rx and can't find anything.

    Is the only way you're interacting with the community this forum or is there a place where you track known issues/fixes and release notes, etc. (like the best practice in OS projects).  The only way I could see this bug was fixed was to run test code.  More importantly though, a 'known issues' list is something any good library user peruses regularly to ensure they're not making use of any borked functionality.

    Anyway, thanks for fixing this one!


    thargy

    Craig Dean (MCPD)
    Chief Executive
    www.webappuk.com

    Please consider marking this as the answer if you have been genuinely helped!

    Friday, November 2, 2012 9:38 AM
  • This was fixed in the latest update. Release notes are pending; stay tuned.
    Monday, November 5, 2012 3:06 AM