Projection over property named Id causes null results

27 views
Skip to first unread message

Jens Pettersson

unread,
Feb 21, 2018, 4:54:28 PM2/21/18
to RavenDB - 2nd generation document database
Hello. We're experiencing a weird behaviour when using a query with a projection that does a Select over a property called Id. It causes NULL results (from the Select) in EVERY scenario we can test, except when I try to run it as a unit test inside the Raven test project in the official repo. That's why the repro isn't a unit test in your code base.

Here's our setup:

Client: 4.0.1 Stable
Server: 4.0.0

We have  a User document that has a list of Tags. Each Tag has an Id-property, but the Tag isn't a document itself (could be a reference object where the Id points to another document, but it isn't in this example):

public class User
{
    public string Id { get; set; }
    public List<Tag> Tags { get; set; }
}

public class Tag
{
    public string Id { get; set; }
    public string Name { get; set; }
}

With the following program:

using (var session = documentStore.OpenAsyncSession())
{
    var user = new User
    {
        Id = "users/1",
        Tags = new List<Tag>
        {
            new Tag
            {
                Id = "tag-id1", 
                Name = "Tag name"
            }
        }
    };

    await session.StoreAsync(user, "users/1");
    await session.SaveChangesAsync();
}

using (var session = documentStore.OpenAsyncSession())
{
    var query = session.Query<User>();

    var projection = from user in query
                        let tagIds = user.Tags.Select(x => x.Id)
                        let tags = user.Tags.Select(x => x.Name)
                        select new
                        {
                            UserId = user.Id,
                            Tags = tags,
                            TagIds = tagIds
                        };

    var result = await projection.FirstAsync();
}

The expectation here is that the result would be:

{
  UserId: "users/1",
  Tags: ["Tag name"],
  TagIds: ["tag-id1"]
}

however, what we get when running this query is:

{
  UserId: "users/1",
  Tags: ["Tag name"],
  TagIds: [null]
}

If I change the property called Id on the Tag class to something else it works as expected.

Here are some images:


Property not called Id:




When looking at the generate RQL code for the different projections, there are a couple of differences:

With a property not called "Id":

{declare function output(user) {
var tagIds = user.Tags.map(function(x){return x.NotJustId;});
var tags = user.Tags.map(function(x){return x.Name;});
return { UserId : id(user), Tags : tags, TagIds : tagIds };
}
from Users as user select output(user)}

vs. a property called "Id":

{declare function output(user) {
var tagIds = user.Tags.map(function(x){return id(x);});
var tags = user.Tags.map(function(x){return x.Name;});
return { UserId : id(user), Tags : tags, TagIds : tagIds };
}
from Users as user select output(user)}


What really bugs me is that the second generated RQL returns the expected results when running it as a test in the Raven code base inheriting from "RavenTestBase".


Any ideas?

//J

Marko Lahma

unread,
Feb 22, 2018, 2:26:08 AM2/22/18
to RavenDB - 2nd generation document database

You need server to be of version 4.0.1 as this projection is done on server side. Fix made it to version 4.0.1

-Marko

Jens Pettersson

unread,
Feb 22, 2018, 2:29:44 AM2/22/18
to RavenDB - 2nd generation document database
Ah ok! I don't see the 4.0.1 Server version on https://ravendb.net/download yet...

Marko Lahma

unread,
Feb 22, 2018, 2:33:58 AM2/22/18
to RavenDB - 2nd generation document database

Hmm.. it used to be there, I have one downloaded myself. But you should be fine with nightly - they are all bug fixes and for me at least nightlies work better for some specific use cases I have.

-Marko

Oren Eini (Ayende Rahien)

unread,
Feb 22, 2018, 2:37:01 AM2/22/18
to ravendb
Use the nightly, yes. We had a missed update for 4.0.1 so we pulled it for 4.0.2 that should be out soon

Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jens Pettersson

unread,
Feb 22, 2018, 2:39:04 AM2/22/18
to RavenDB - 2nd generation document database
Thanks guys. It explains a lot (about why it worked in a unit test in the official code base and hence, I'm not crazy)
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages