Gremlinq / ExRam.Gremlinq

A .NET object-graph-mapper for Apache TinkerPop™ Gremlin enabled databases.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

V() guids array serialization

aristovg opened this issue · comments

Hi,
seems that guids array are not properly serialized in calls to V(params object[] ids)

        [Fact]
        public void VGuid()
        {
            var strings = new[] { "string1", "string2" };

            g.V(strings).Should().SerializeToGroovy<CosmosDbGroovyGremlinQueryElementVisitor>("g.V(_a, _b)")
                .WithParameters("string1", "string2");

            var guid1 = Guid.NewGuid();
            var guid2 = Guid.NewGuid();

            var guids = new[] {guid1, guid2};

            g.V(guids).Should().SerializeToGroovy<CosmosDbGroovyGremlinQueryElementVisitor>("g.V(_a, _b)")
                .WithParameters(guid1, guid2);
        }

Guid serialization ends with a query g.V(_a), and parameter serialized to a complex object that looks like this:
{{80263ee2-6e17-4643-af7c-a613bb6254f9}, {5dbc9a0c-a9c1-4d01-afa7-df822f664ec7}}.

This fails in Azure CosmosDb, probably in other implementations as well.

It's because you are passing a Guid array into a method that takes params object[]. Thus, the guid array will inevitably end up as the first element in an object array. Gremlinq doesn't do any magic here to determine you meant something else. Replace

var guids = new[] {guid1, guid2};

by

var guids = new object[] {guid1, guid2};

and you should be fine.

More technically: Array covariance doesn't work from T[] to object[] when T is a struct.

Yeah, that makes sense. We actually used the new object[] approach as a workaround, so I guess it's more of "nice-to-have" feature (maybe a generic constraint of some sort, or just an exception).

Thanks anyway, keep up the amazing work.