Marten: Exceptions thrown for various Duplicate field scenarios involving nulls

Created on 18 Dec 2018  路  2Comments  路  Source: JasperFx/marten

I've found a couple of scenarios where exceptions are being thrown when storing documents due to null values for Duplicate fields.

[Fact]
public void when_field_is_null_due_to_nesting()
{
    StoreOptions(_ => _.Schema.For<Target>().Duplicate(t => t.Inner.Number));

    using (var session = theStore.OpenSession())
    {
        session.Store(new Target
        {
            Number = 1,
            Inner = null
        });

        session.SaveChanges();
    }

    using (var session = theStore.OpenSession())
    {
        session.Query<Target>().Where(x => x.Number == 1)
            .ToArray()
            .Select(x => x.Number)
            .ShouldHaveTheSameElementsAs(1);
    }
}

Throws a NullReferenceException.

[Fact]
public void when_string_enum_is_null_due_to_nullable_type()
{
    StoreOptions(_ =>
    {
        _.Serializer(new JsonNetSerializer{EnumStorage = EnumStorage.AsString});
        _.Schema.For<Target>().Duplicate(t => t.NullableColor);
    });

    using (var session = theStore.OpenSession())
    {
        session.Store(new Target
        {
            Number = 1,
            NullableColor = null
        });

        session.SaveChanges();
    }

    using (var session = theStore.OpenSession())
    {
        session.Query<Target>().Where(x => x.Number == 1)
            .ToArray()
            .Select(x => x.Number)
            .ShouldHaveTheSameElementsAs(1);
    }
}

Throws ArgumentNullException when calling System.RuntimeType.GetEnumName() internally.
N.B. I added a NullableColor property of type Colours? to the Target class for this one.

I'd be happy to contribute a PR if you accept them and these scenarios are valid use cases.

bug

Most helpful comment

Cheers @oskardudycz. I'll report back when i have something.

All 2 comments

@richardoliver-umusic all of your cases looks valid to me, we'd be happy to take PR with fixes :)

Cheers @oskardudycz. I'll report back when i have something.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jinhong- picture jinhong-  路  7Comments

mhabibal13 picture mhabibal13  路  5Comments

jeremydmiller picture jeremydmiller  路  6Comments

ppumkin picture ppumkin  路  4Comments

jeremydmiller picture jeremydmiller  路  7Comments