edgedb / edgedb-net

The official .NET client library for EdgeDB
https://edgedb.com
Apache License 2.0
83 stars 9 forks source link

Issue with query parameters when using optionals with different underlying types #65

Closed Darkle closed 1 year ago

Darkle commented 1 year ago

With the following schema:

module default {
  type Settings {
    required uniqueId: str {
      default := "settings"; 
      constraint exclusive;
    };
    required numberMediaDownloadsAtOnce: int32 {
      default := 2;
      constraint min_value(1);
    };
    required updateAllDay: bool {
      default := true;
    };
  };
}

And the following code:

let queryParams =
    {| numberMediaDownloadsAtOnce = Some 3
       updateAllDay = Some false |}

dbClient.ExecuteAsync(
    """
        update Settings 
        filter .uniqueId = "settings"
        set {
            numberMediaDownloadsAtOnce := <optional int32>$numberMediaDownloadsAtOnce ?? .numberMediaDownloadsAtOnce,
            updateAllDay := <optional bool>$updateAllDay ?? .updateAllDay       
        }         
        """,
    queryParams
)

I get an error of:

Error: EdgeDB.EdgeDBException: Failed to execute query
 ---> System.ArgumentException: Object of type 'Microsoft.FSharp.Core.FSharpOption`1[System.Int32]' cannot be converted to type 'Microsoft.FSharp.Core.FSharpOption`1[System.Boolean]'.
   at System.RuntimeType.CheckValue(Object& value, ParameterCopyBackAction& copyBack, Binder binder, CultureInfo culture, BindingFlags invokeAttr)
   at System.Reflection.MethodBase.CheckArguments(Span`1 copyOfParameters, IntPtr* byrefParameters, Span`1 shouldCopyBack, ReadOnlySpan`1 parameters, RuntimeType[] sigTypes, Binder binder, CultureInfo culture, BindingFlags invokeAttr)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at EdgeDB.Utils.FSharp.FSharpOptionInterop..ctor(Object obj)
   at EdgeDB.Utils.FSharp.FSharpOptionInterop.TryGet(Object value, FSharpOptionInterop& option)
   at EdgeDB.Binary.Codecs.ObjectCodec.Serialize(PacketWriter& writer, Object value, CodecContext context)
   at EdgeDB.Binary.Codecs.ObjectCodec.SerializeArguments(PacketWriter& writer, Object value, CodecContext context)
   at EdgeDB.Binary.Codecs.BaseArgumentCodec`1.EdgeDB.Binary.Codecs.IArgumentCodec.SerializeArguments(PacketWriter& writer, Object value, CodecContext context)
   at EdgeDB.CodecExtensions.SerializeArguments(IArgumentCodec codec, EdgeDBBinaryClient client, Object value)
   at EdgeDB.EdgeDBBinaryClient.ExecuteInternalAsync(String query, IDictionary`2 args, Nullable`1 cardinality, Nullable`1 capabilities, IOFormat format, Boolean isRetry, Boolean implicitTypeName, CancellationToken token)
   --- End of inner exception stack trace ---
   at EdgeDB.EdgeDBBinaryClient.ExecuteInternalAsync(String query, IDictionary`2 args, Nullable`1 cardinality, Nullable`1 capabilities, IOFormat format, Boolean isRetry, Boolean implicitTypeName, CancellationToken token)
   at EdgeDB.EdgeDBBinaryClient.ExecuteAsync(String query, IDictionary`2 args, Nullable`1 capabilities, CancellationToken token)
   at EdgeDB.EdgeDBClient.ExecuteAsync(String query, IDictionary`2 args, Nullable`1 capabilities, CancellationToken token)
   at EdgeDB.EdgeDBClient.ExecuteAsync(String query, IDictionary`2 args, Nullable`1 capabilities, CancellationToken token)
   at Program.Pipe #1 input at line 10@10.MoveNext() in /home/coop/Coding/edgedb-issue-4/Program.fs:line 38

Simple repro: https://github.com/Darkle/edgedb-issue-4

It seems to only happen if the optionals in the queryParams are of different types (eg option<int32> and option<bool>), if they are of the same type the error does not occur.

Versions :