Repodb: Bug: Nullables not working on SQLite (F#)

Created on 16 Sep 2020  路  12Comments  路  Source: mikependon/RepoDB

I have a a record defined as follows:

[<CLIMutable>]
type CommandEntity =
  { Id: int
    AggregateId: Guid
    CommandId: Guid
    CausationId: Guid
    CorrelationId: Guid
    CommandPayload: string
    PayloadType: string
    QueueName: string
    ExpectedVersion: System.Nullable<System.Int64>
    ProcessId: obj }

RepoDb.Converter.ConversionType <- ConversionType.Automatic
SqLiteBootstrap.Initialize()

Apparently inserting using InsertAll throws up an error about the nullable type.

Unhandled exception. System.ArgumentException: Expression of type 'System.Nullable`1[System.Int64]' cannot be used for parameter of type 'System.Object' of method 'Int64 ToInt64(System.Object)' (Parameter 'arg0')
   at System.Dynamic.Utils.ExpressionUtils.ValidateOneArgument(MethodBase method, ExpressionType nodeKind, Expression arguments, ParameterInfo pi, String methodParamName, String argumentParamName, Int32 index)
   at System.Linq.Expressions.Expression.Call(MethodInfo method, Expression arg0)
   at RepoDb.Reflection.Compiler.ConvertExpressionToSystemConvertExpression(Expression expression, Type toType)
   at RepoDb.Reflection.Compiler.ConvertExpressionWithAutomaticConversion(Expression expression, Type fromType, Type toType)
   at RepoDb.Reflection.Compiler.GetPropertyValueWithAutomaticConversionExpression(Expression entityExpression, ClassProperty classProperty, DbField dbField)
   at RepoDb.Reflection.Compiler.GetEntityInstancePropertyValueExpression(Expression entityExpression, ClassProperty classProperty, DbField dbField)
   at RepoDb.Reflection.Compiler.GetDbParameterValueAssignmentExpression(ParameterExpression parameterVariableExpression, Expression entityExpression, ParameterExpression propertyExpression, ClassProperty classProperty, DbField dbField, IDbSetting dbSetting)
   at RepoDb.Reflection.Compiler.GetParameterAssignmentExpression(ParameterExpression commandParameterExpression, Int32 entityIndex, Expression entityExpression, ParameterExpression propertyExpression, DbField dbField, ClassProperty classProperty, ParameterDirection direction, IDbSetting dbSetting)
   at RepoDb.Reflection.Compiler.GetPropertyFieldExpression(ParameterExpression commandParameterExpression, ParameterExpression entityExpression, FieldDirection fieldDirection, Int32 entityIndex, IDbSetting dbSetting)
   at RepoDb.Reflection.Compiler.GetIndexDbParameterSetterExpression[TResult](ParameterExpression commandParameterExpression, Expression entitiesParameterExpression, IEnumerable`1 fieldDirections, Int32 entityIndex, IDbSetting dbSetting)
   at RepoDb.Reflection.Compiler.CompileDataEntityListDbParameterSetter[TEntity](IEnumerable`1 inputFields, IEnumerable`1 outputFields, Int32 batchSize, IDbSetting dbSetting)
   at RepoDb.Reflection.FunctionFactory.CompileDataEntityListDbParameterSetter[TEntity](IEnumerable`1 inputFields, IEnumerable`1 outputFields, Int32 batchSize, IDbSetting dbSetting)
   at RepoDb.FunctionCache.DataEntityListDbParameterSetterCache`1.Get(String cacheKey, IEnumerable`1 inputFields, IEnumerable`1 outputFields, Int32 batchSize, IDbSetting dbSetting)
   at RepoDb.FunctionCache.GetDataEntityListDbParameterSetterCompiledFunction[TEntity](String cacheKey, IEnumerable`1 inputFields, IEnumerable`1 outputFields, Int32 batchSize, IDbSetting dbSetting)
   at RepoDb.Contexts.Providers.InsertAllExecutionContextProvider.CreateInternal[TEntity](IDbConnection connection, String tableName, IEnumerable`1 dbFields, Int32 batchSize, IEnumerable`1 fields, String hints, IDbTransaction transaction, IStatementBuilder statementBuilder)
   at RepoDb.Contexts.Providers.InsertAllExecutionContextProvider.Create[TEntity](IDbConnection connection, String tableName, Int32 batchSize, IEnumerable`1 fields, String hints, IDbTransaction transaction, IStatementBuilder statementBuilder)
   at RepoDb.DbConnectionExtension.InsertAllInternalBase[TEntity](IDbConnection connection, String tableName, IEnumerable`1 entities, Int32 batchSize, IEnumerable`1 fields, String hints, Nullable`1 commandTimeout, IDbTransaction transaction, ITrace trace, IStatementBuilder statementBuilder)
   at RepoDb.DbConnectionExtension.InsertAllInternal[TEntity](IDbConnection connection, String tableName, IEnumerable`1 entities, Int32 batchSize, IEnumerable`1 fields, String hints, Nullable`1 commandTimeout, IDbTransaction transaction, ITrace trace, IStatementBuilder statementBuilder)
   at RepoDb.DbConnectionExtension.InsertAll[TEntity](IDbConnection connection, IEnumerable`1 entities, Int32 batchSize, IEnumerable`1 fields, String hints, Nullable`1 commandTimeout, IDbTransaction transaction, ITrace trace, IStatementBuilder statementBuilder)
   at Db.Fn.writeEvents() in /Users/swoorup.joshi/RiderProjects/Playground/Playground/Db.fs:line 71
Fixed bug deployed

All 12 comments

There are massive changes on our compiler by now. The stacktrace provided is not enough for us to identify the compiler version. Can you specify which version of RepoDB this happens?

@mikependon

RepoDb 1.12.0-beta3
RepoDb.SqLite 1.1.0-beta1

Thanks! Will get back to you soon. It happened on the new compiler. We will cover this on the next release.

Updated the stack trace. 馃憤

I will issue a beta release for you. When do you need the fix for this?

Not urgent @mikependon Thank you. Ideally would prefer waiting on F# option types.
I can use the none beta version which appears to work fine for this case.

Let me know if you'd need further information.

Thanks @Swoorup . Will give you further updates soon.

Just FYI, before I start the investigation to this. The Integration Tests models used are heavy in nullable properties. Please see them here.

Can confirm this also happens for postgres using the same version.

The fix is now available at RepoDb v1.12.0-beta4 and RepoDb.SqLite v1.1.0-beta2.

> Install-Package RepoDb -version 1.12.0-beta4
> Install-Package RepoDb.SqLite -version 1.1.0-beta2

Please note that the fix to this also applies to the other DB Providers (i.e: SQL Server, PostgreSQL and MySQL).

Appears to be resolved.

Thanks for the verification.

Was this page helpful?
0 / 5 - 0 ratings