Skip to content

Generated code does not compile for EntityAttribute on Guid property with OnMissing.ThrowException #2207

@JMounier

Description

@JMounier

Describe the bug

Using [Entity("MyGuidProp", OnMissing = OnMissing.ThrowException)] breaks code generation when MyGuidProp does not define the ?. Null-conditional operator (eg. when using Guid as the table's primary key).

Generated code from the To Reproduce example:

            // Trying to load the existing Saga data
            var operation = await solidContext.FindAsync<Models.Operation>(((Operator.RequireEntityByGuid)context.Envelope.Message).OperationId).ConfigureAwait(false);
            // Write ProblemDetails if this required object is null
            if (operation == null)
            {
                throw new Wolverine.Persistence.RequiredDataMissingException("Unknown Operation with identity {Id}".Replace("{Id}", ((Operator.RequireEntityByGuid)context.Envelope.Message).OperationId?.ToString() ?? ""));
            }

Resulting error:

Operator '?' cannot be applied to operand of type 'Guid' CS0023

This regression was introduced in #2147 (v5.15.0)

To Reproduce

public class Operation
{
    required Guid Id { get; set; }
}

public sealed record RequireEntityByGuid(Guid OperationId);

public class RequiredEntityByGuidHandler
{
    public static void Handle(
        RequireEntityByGuid __,
        [Entity("OperationId", OnMissing = OnMissing.ThrowException, Required = true)] Operation _
    ) { }
}

Expected behavior

Generated code should be compile.

Additional context

It is possible to workaround the issue by providing a MissingMessage to the EntityAttribute.

Note

It's even possible to have wolverine inject the found property value by using {0} in the message (cf. src/Wolverine/Persistence/ThrowRequiredDataMissingExceptionFrame.cs).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions