Summary
Exception thrown when calling ApolloStore#remove(cacheKeys: List<CacheKey>): ApolloStoreOperation<Int>. CacheKeys are valid and exist in normalized cache.
Version
2.2.2
Description
Error:
com.apollographql.apollo.exception.ApolloException: Failed to perform store operation
cause: java.lang.ClassCastException: com.squareup.sqldelight.TransactionWrapper cannot be cast to com.squareup.sqldelight.Transacter$Transaction
stactTrace:
com.apollographql.apollo.cache.normalized.sql.SqlNormalizedCache$deleteRecord$1.invoke(SqlNormalizedCache.kt:11)
com.squareup.sqldelight.TransacterImpl.transactionWithWrapper(Transacter.kt:218)
com.squareup.sqldelight.TransacterImpl.transaction(Transacter.kt:197)
com.squareup.sqldelight.Transacter$DefaultImpls.transaction$default(Transacter.kt:82)
com.apollographql.apollo.cache.normalized.sql.SqlNormalizedCache.deleteRecord(SqlNormalizedCache.kt:96)
com.apollographql.apollo.cache.normalized.sql.SqlNormalizedCache.remove(SqlNormalizedCache.kt:45)
com.apollographql.apollo.cache.normalized.lru.LruNormalizedCache.remove(LruNormalizedCache.kt:63)
com.apollographql.apollo.cache.normalized.OptimisticNormalizedCache.remove(OptimisticNormalizedCache.kt:35)
com.apollographql.apollo.cache.normalized.NormalizedCache.remove(NormalizedCache.kt:109)
com.apollographql.apollo.internal.RealApolloStore$5$1.execute(RealApolloStore.java:159)
com.apollographql.apollo.internal.RealApolloStore$5$1.execute(RealApolloStore.java:155)
com.apollographql.apollo.internal.RealApolloStore.writeTransaction(RealApolloStore.java:182)
com.apollographql.apollo.internal.RealApolloStore$5.perform(RealApolloStore.java:155)
com.apollographql.apollo.internal.RealApolloStore$5.perform(RealApolloStore.java:153)
com.apollographql.apollo.cache.normalized.ApolloStoreOperation$enqueue$1.run(ApolloStoreOperation.kt:55)
This seems to be an incompatibility with SqlDelight 1.4.0 coming from this change. I'm not 100% clear what the correct solution would be there. Reverting your SqlDelight dependencies to 1.3.0 should work although it's not a solution in the long run.
What version of SqlDelight does Apollo-Android use? 1.3.0?
Yes, 1.3.0.
Ok, so I will test it with 1.3.0 version and gonna add an issue in SqlDelight repo.
Reproduction repo there: https://github.com/martinbonnin/apollo-android-samples/tree/master/sqlite-test
Run ./gradlew test to make the test fail
One more question: method remove(key: CacheKey) has optional cascade flag. Why this flag might not be set for list of CacheKey? Is it default true?
One more question: method remove(key: CacheKey) has optional cascade flag. Why this flag might not be set for list of CacheKey? Is it default true?
Good question, I'm not sure. Can you think of a use case where this is a problem? Please file a separate issue if it's the case.
Also, I filed an issue in SQLDelight: https://github.com/cashapp/sqldelight/issues/1865
The next version (2.3.0) will be compiled against SqlDelight 1.4.0 and should not have this issue anymore.
Sorry, I don't understand. SqlDelight 1.4.0 has the described bug so why are you going to bump version?
The problem is SqlDelight 1.4.0 is not binary compatible with classes compiled against SqlDelight 1.3.0. If we compile Apollo against 1.4.0, the problem should disappear.
In other words, the jar from apollo-android:2.2.2 contains a reference to a method that is present in SqlDelight 1.3.0 but not in SqlDelight 1.4.0.
apollo-android 2.3.0 is just out if you want to try.