hfhbd / postgres-native-sqldelight

A Kotlin native Postgres driver for SqlDelight.
https://postgresnative.softwork.app/
Apache License 2.0
36 stars 3 forks source link

Using Ktor Serialization KotlinX Json causes kotlinx.serialization/MissingFieldException #100

Closed jonas-tm closed 2 years ago

jonas-tm commented 2 years ago

Hi, The combination of the your Postgres Driver and Kotlinx Json Serialization causes a compile error on my M1 Mac: kotlinx.serialization/MissingFieldException.<init>|399804788095754142

As soon as I remove either Kotlinx Json Serialization or the Postgres Driver the problem is gone.

build.gradle.kts

val ktor_version = "2.1.3"
val kotlin_version = "1.7.21"
val psql_driver_version = "0.0.4"
val kotlin_coroutine = "1.6.4"

plugins {
    kotlin("multiplatform") version "1.7.21"
    kotlin("plugin.serialization") version "1.7.21"

    id("app.cash.sqldelight") version "2.0.0-alpha04"
}

group = "com.test"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

sqldelight {
    database("NativePostgres") {
        dialect("app.softwork:postgres-native-sqldelight-dialect:$psql_driver_version")
        packageName = "com.test.sqldelight"
    }
    linkSqlite = false
}

kotlin {
    val commonTarget = macosArm64("common")

    commonTarget.apply {
        binaries {
            executable {
                entryPoint = "com.test.main"
            }
        }
    }

    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation("io.ktor:ktor-server-core:$ktor_version")
                implementation("io.ktor:ktor-server-cio:$ktor_version")

                implementation("app.softwork:postgres-native-sqldelight-driver:$psql_driver_version")

                implementation("io.ktor:ktor-serialization-kotlinx-json:$ktor_version")

            }
        }
    }
}

compile error:

Compilation failed: Expecting descriptor for kotlinx.serialization/MissingFieldException.<init>|399804788095754142[0]

 * Source files: 
 * Compiler version info: Konan: 1.7.21 / Kotlin: 1.7.21
 * Output kind: STATIC_CACHE

e: java.lang.IllegalStateException: Expecting descriptor for kotlinx.serialization/MissingFieldException.<init>|399804788095754142[0]
    at org.jetbrains.kotlin.backend.konan.serialization.KonanIrLinker$KonanCachedLibraryModuleDeserializer.tryDeserializeIrSymbol(KonanIrlinker.kt:644)
    at org.jetbrains.kotlin.backend.common.serialization.BasicIrModuleDeserializer.deserializeIrSymbol(BasicIrModuleDeserializer.kt:111)
    at org.jetbrains.kotlin.backend.common.serialization.FileDeserializationState$symbolDeserializer$3.invoke(IrFileDeserializer.kt:88)
    at org.jetbrains.kotlin.backend.common.serialization.FileDeserializationState$symbolDeserializer$3.invoke(IrFileDeserializer.kt:77)
    at org.jetbrains.kotlin.backend.common.serialization.IrSymbolDeserializer.deserializeIrSymbolData(IrSymbolDeserializer.kt:67)
    at org.jetbrains.kotlin.backend.common.serialization.IrSymbolDeserializer.deserializeIrSymbol(IrSymbolDeserializer.kt:84)
    at org.jetbrains.kotlin.backend.common.serialization.IrDeclarationDeserializer.deserializeIrSymbolAndRemap$ir_serialization_common(IrDeclarationDeserializer.kt:211)
    at org.jetbrains.kotlin.backend.common.serialization.IrBodyDeserializer.deserializeConstructorCall(IrBodyDeserializer.kt:244)
    at org.jetbrains.kotlin.backend.common.serialization.IrBodyDeserializer.deserializeOperation(IrBodyDeserializer.kt:805)
    at org.jetbrains.kotlin.backend.common.serialization.IrBodyDeserializer.deserializeExpression(IrBodyDeserializer.kt:818)
    at org.jetbrains.kotlin.backend.common.serialization.IrBodyDeserializer.deserializeThrow(IrBodyDeserializer.kt:540)
    at org.jetbrains.kotlin.backend.common.serialization.IrBodyDeserializer.deserializeOperation(IrBodyDeserializer.kt:797)
    at org.jetbrains.kotlin.backend.common.serialization.IrBodyDeserializer.deserializeExpression(IrBodyDeserializer.kt:818)
    at org.jetbrains.kotlin.backend.common.serialization.IrBodyDeserializer.deserializeStatement$ir_serialization_common(IrBodyDeserializer.kt:138)
    at org.jetbrains.kotlin.backend.common.serialization.IrBodyDeserializer.deserializeBlock(IrBodyDeserializer.kt:154)
    at org.jetbrains.kotlin.backend.common.serialization.IrBodyDeserializer.deserializeOperation(IrBodyDeserializer.kt:769)
    at org.jetbrains.kotlin.backend.common.serialization.IrBodyDeserializer.deserializeExpression(IrBodyDeserializer.kt:818)
    at org.jetbrains.kotlin.backend.common.serialization.IrBodyDeserializer.deserializeCatch(IrBodyDeserializer.kt:111)
    at org.jetbrains.kotlin.backend.common.serialization.IrBodyDeserializer.deserializeStatement$ir_serialization_common(IrBodyDeserializer.kt:134)
    at org.jetbrains.kotlin.backend.common.serialization.IrBodyDeserializer.deserializeTry(IrBodyDeserializer.kt:547)
    at org.jetbrains.kotlin.backend.common.serialization.IrBodyDeserializer.deserializeOperation(IrBodyDeserializer.kt:798)
    at org.jetbrains.kotlin.backend.common.serialization.IrBodyDeserializer.deserializeExpression(IrBodyDeserializer.kt:818)
    at org.jetbrains.kotlin.backend.common.serialization.IrBodyDeserializer.deserializeStatement$ir_serialization_common(IrBodyDeserializer.kt:138)
    at org.jetbrains.kotlin.backend.common.serialization.IrBodyDeserializer.deserializeBlockBody(IrBodyDeserializer.kt:95)
    at org.jetbrains.kotlin.backend.common.serialization.IrBodyDeserializer.deserializeStatement$ir_serialization_common(IrBodyDeserializer.kt:130)
    at org.jetbrains.kotlin.backend.common.serialization.IrDeclarationDeserializer.deserializeStatementBody(IrDeclarationDeserializer.kt:547)
    at org.jetbrains.kotlin.backend.common.serialization.IrDeclarationDeserializer$withDeserializedIrFunctionBase$1$1$1$1.invoke(IrDeclarationDeserializer.kt:575)
    at org.jetbrains.kotlin.backend.common.serialization.IrDeclarationDeserializer$withDeserializedIrFunctionBase$1$1$1$1.invoke(IrDeclarationDeserializer.kt:564)
    at org.jetbrains.kotlin.backend.common.serialization.IrDeclarationDeserializer.withBodyGuard(IrDeclarationDeserializer.kt:509)
    at org.jetbrains.kotlin.backend.common.serialization.IrDeclarationDeserializer.access$withBodyGuard(IrDeclarationDeserializer.kt:64)
    at org.jetbrains.kotlin.backend.common.serialization.IrDeclarationDeserializer.deserializeIrFunction$ir_serialization_common(IrDeclarationDeserializer.kt:1099)
    at org.jetbrains.kotlin.backend.common.serialization.IrDeclarationDeserializer.deserializeDeclaration(IrDeclarationDeserializer.kt:788)
    at org.jetbrains.kotlin.backend.common.serialization.IrDeclarationDeserializer.deserializeDeclaration$default(IrDeclarationDeserializer.kt:782)
    at org.jetbrains.kotlin.backend.common.serialization.IrDeclarationDeserializer.deserializeIrClass(IrDeclarationDeserializer.kt:375)
    at org.jetbrains.kotlin.backend.common.serialization.IrDeclarationDeserializer.deserializeDeclaration(IrDeclarationDeserializer.kt:787)
    at org.jetbrains.kotlin.backend.common.serialization.IrDeclarationDeserializer.deserializeDeclaration$default(IrDeclarationDeserializer.kt:782)
    at org.jetbrains.kotlin.backend.common.serialization.IrFileDeserializer.deserializeDeclaration(IrFileDeserializer.kt:40)
    at org.jetbrains.kotlin.backend.common.serialization.FileDeserializationState.deserializeAllFileReachableTopLevel(IrFileDeserializer.kt:135)
    at org.jetbrains.kotlin.backend.common.serialization.BasicIrModuleDeserializer$ModuleDeserializationState.deserializeReachableDeclarations(BasicIrModuleDeserializer.kt:190)
    at org.jetbrains.kotlin.backend.common.serialization.BasicIrModuleDeserializer.deserializeReachableDeclarations(BasicIrModuleDeserializer.kt:158)
    at org.jetbrains.kotlin.backend.common.serialization.KotlinIrLinker.deserializeAllReachableTopLevels(KotlinIrLinker.kt:111)
    at org.jetbrains.kotlin.backend.common.serialization.KotlinIrLinker.findDeserializedDeclarationForSymbol(KotlinIrLinker.kt:129)
    at org.jetbrains.kotlin.backend.common.serialization.KotlinIrLinker.deserializeOrResolveDeclaration(KotlinIrLinker.kt:169)
hfhbd commented 2 years ago

Sounds like https://github.com/Kotlin/kotlinx.serialization/issues/2024

But this driver does not use kotlinx serialization, "only" ktor. Workaround: update both kotlinx serialization (core and json) to 1.4.0.

hfhbd commented 2 years ago

Edit: Of course I use kotlinx serialization: my uuid library uses 1.4.0

jonas-tm commented 2 years ago

Thanks for the fast reply. This is indeed the problem.

Had to add the following to force a consistent version:

                implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.4.0") {
                    version { strictly("1.4.0") }
                }
                implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.0") {
                    version { strictly("1.4.0") }
                }