🐛 Bug Report: Crash when trying to createRow with transaction

Aperta
#96 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
52/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
android, kotlin
Ambito
mobile

Direzione di ricerca

Inizia dal metodo in Row.kt e dai cast che falliscono alle righe indicate, quindi segui la conversione della risposta di createRow in TablesDb.kt. Riproduci il caso transazionale e verifica che sia possibile creare una riga senza $createdAt o $updatedAt, mentre il caso non transazionale continua a funzionare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

👟 Reproduction steps

The new sdk for Android has a bug when trying to creating a row using a transaction.

Main problem is that the Row is looking for a $createdAt property when, if using a transaction, does not make sense because has not been executed. App crashes on Row.kt in the following lines:

        @Suppress("UNCHECKED_CAST")
        fun <T> from(
            map: Map<String, Any>,
            nestedType: Class<T>
        ) = Row<T>(
            id = map["\$id"] as String,
            sequence = (map["\$sequence"] as Number).toLong(),
            tableId = map["\$tableId"] as String,
            databaseId = map["\$databaseId"] as String,
            createdAt = map["\$createdAt"] as String,
            updatedAt = map["\$updatedAt"] as String,
            permissions = map["\$permissions"] as List<String>,
            data = map["data"]?.jsonCast(to = nestedType) ?: map.jsonCast(to = nestedType)
        )

One possible solution (markeing the fields as nullable) is the following:

data class Row<T>(
    /**
     * Row ID.
     */
    @SerializedName("\$id")
    val id: String,

.....

    /**
     * Row creation date in ISO 8601 format.
     */
    @SerializedName("\$createdAt")
    val createdAt: String?,

    /**
     * Row update date in ISO 8601 format.
     */
    @SerializedName("\$updatedAt")
    val updatedAt: String?,
....
createdAt = map["\$createdAt"] as String?,
updatedAt = map["\$updatedAt"] as String?,

I removed the transaction attribute when debuging the code and it worked perfectly.

👍 Expected behavior

Work as well as if no transaction is place

👎 Actual Behavior

The app crashes, here is the error from the logcat

  E  FATAL EXCEPTION: OkHttp Dispatcher (Ask Gemini)
  Process: com.X.X, PID: 17597
 java.lang.NullPointerException: null cannot be cast to non-null type kotlin.String at io.appwrite.models.Row$Companion.from(Row.kt:99)
at io.appwrite.services.TablesDB$createRow$converter$1.invoke(TablesDb.kt:316)
at io.appwrite.services.TablesDB$createRow$converter$1.invoke(TablesDb.kt:314)
at io.appwrite.Client$awaitResponse$2$1.onResponse(Client.kt:602)
at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:519)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:923)
🎲 Appwrite version

Version 1.8.x

💻 Operating system

Linux

🧱 Your Environment

Appwrite SDK 11.3.0

👀 Have you spent some time to check if this issue has been raised before?
  • I checked and didn't find similar issue
🏢 Have you read the Code of Conduct?
Lingua principale
Kotlin
Stelle
156
Fork
29
Merge medio
8h 49m
PR unite (30g)
5

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di appwrite/sdk-for-android

Tutte le issue di appwrite/sdk-for-android

Issue simili

Altre issue su Kotlin

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.