Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shrinking a query observed by OffsetQueryPagingSource in Android paging3 causes an exception #2591

Closed
sproctor opened this issue Sep 23, 2021 · 2 comments
Labels
Milestone

Comments

@sproctor
Copy link
Contributor

SQLDelight Version

1.5.1

Application Operating System

Android

Describe the Bug

The SQLDelight paging3 extension does not properly handle refresh.

This line could be something like:

val offset = if (key >= count) {
        maxOf(0, count - params.loadSize)
    } else {
        key
    }

Room has a good example of implementing paging: https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:room/room-paging/src/main/kotlin/androidx/room/paging/LimitOffsetPagingSource.kt

Stacktrace

java.lang.IndexOutOfBoundsException
        at com.squareup.sqldelight.android.paging3.OffsetQueryPagingSource$load$2$1.invoke(OffsetQueryPagingSource.kt:40)
        at com.squareup.sqldelight.android.paging3.OffsetQueryPagingSource$load$2$1.invoke(OffsetQueryPagingSource.kt:38)
        at com.squareup.sqldelight.TransacterImpl.transactionWithWrapper(Transacter.kt:235)
        at com.squareup.sqldelight.TransacterImpl.transactionWithResult(Transacter.kt:221)
        at com.squareup.sqldelight.Transacter$DefaultImpls.transactionWithResult$default(Transacter.kt:61)
        at com.squareup.sqldelight.android.paging3.OffsetQueryPagingSource$load$2.invokeSuspend(OffsetQueryPagingSource.kt:38)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
@sproctor sproctor added the bug label Sep 23, 2021
@ConorGarry
Copy link

Having same issue in 1.5.2.

I have removed any potential deletions to ensure that I'm not concurrently altering the underlying database data during updates.

@veyndan
Copy link
Collaborator

veyndan commented Dec 7, 2022

This should be resolved by #3396 which is in 2.0.0-alpha04.

@veyndan veyndan closed this as completed Dec 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants