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
IndexOutOfBoundsException In OffsetQueryPagingSource #2434
Comments
It appears to be happening when key == count every time. I'm not sure I understand the relationship between key and count and why they cannot be equal? |
Hi @kkovach. Are you able to provide a sample reproduction that I can inspect? |
Hey @kevincianfarini. I've been working with this a little more and I am wondering if this has to do with the getRefreshKey implementation? Could it be that I'm getting an anchor position that is outside the bounds of the query count when scrolling because of timing or something? It always seems to happen when I am scrolling and loading more data. Also, it always happens that key is equal to count when it fails. I went ahead and copied the class locally and change the getRefreshKey to the following...
I believe this makes sense? And I am no longer getting any index out of bounds exceptions. Thoughts? Thanks. |
@kkovach I'm not sure! It's difficult to debug without a small sample project that has a reproduction of the bug. Do you think you'd be able to isolate one? |
@kevincianfarini I'll see what I can do when I get some time. |
I'm also seeing this error. Curious if i'm implementing something incorrectly, or something else is up.. |
Ahh, I think it was because the initial page size was different than subsequent page sizes. Setting initial and page size in the This is a quote from the sqldelight docs:
|
Hi @jakeaaron! The piece you've quoted from the documentation should only apply to the keyset paging functionality. If you're using offset based paging and still seeing this issue, I would be extremely appreciative if you could conjure a reproduction sample for me that I could investigate. |
@kkovach I suspect that
It's possible that the underlying data source is experiencing a deletion event, which invalidates the data source. Upon invalidation, the refresh key that's grabbed off of the current source is out of bounds of the newly created source. I can try to write an integration test to confirm this behavior, and hopefully fix it. |
It's possible that on a paging source that's not in the initial generation, we fail with an `IndexOutOfBoundsException`. This is caused when the underlying data source undergoes a delete, which then invalidates the paging source, which then calls `getRefreshKey`. In the event that the the refresh key is the very last index of the previous paging source, we would fail with the above exception because that index does not exist in the next generation paging source. Closes cashapp#2434.
It's possible that on a paging source that's not in the initial generation, we fail with an `IndexOutOfBoundsException`. This is caused when the underlying data source undergoes a delete, which then invalidates the paging source, which then calls `getRefreshKey`. In the event that the the refresh key is the very last index of the previous paging source, we would fail with the above exception because that index does not exist in the next generation paging source. Closes cashapp#2434.
It's possible that on a paging source that's not in the initial generation, we fail with an `IndexOutOfBoundsException`. This is caused when the underlying data source undergoes a delete, which then invalidates the paging source, which then calls `getRefreshKey`. In the event that the the refresh key is the very last index of the previous paging source, we would fail with the above exception because that index does not exist in the next generation paging source. Closes cashapp#2434.
It's possible that on a paging source that's not in the initial generation, we fail with an `IndexOutOfBoundsException`. This is caused when the underlying data source undergoes a delete, which then invalidates the paging source, which then calls `getRefreshKey`. In the event that the the refresh key is the very last index of the previous paging source, we would fail with the above exception because that index does not exist in the next generation paging source. Closes cashapp#2434.
I'm experiencing this in 1.5.1 |
It's possible that on a paging source that's not in the initial generation, we fail with an `IndexOutOfBoundsException`. This is caused when the underlying data source undergoes a delete, which then invalidates the paging source, which then calls `getRefreshKey`. In the event that the the refresh key is the very last index of the previous paging source, we would fail with the above exception because that index does not exist in the next generation paging source. Closes cashapp#2434.
to reduce the number of notifications, which mitigates the impact of cashapp/sqldelight#2434.
It's possible that on a paging source that's not in the initial generation, we fail with an `IndexOutOfBoundsException`. This is caused when the underlying data source undergoes a delete, which then invalidates the paging source, which then calls `getRefreshKey`. In the event that the the refresh key is the very last index of the previous paging source, we would fail with the above exception because that index does not exist in the next generation paging source. Closes cashapp#2434.
It's possible that on a paging source that's not in the initial generation, we fail with an `IndexOutOfBoundsException`. This is caused when the underlying data source undergoes a delete, which then invalidates the paging source, which then calls `getRefreshKey`. In the event that the the refresh key is the very last index of the previous paging source, we would fail with the above exception because that index does not exist in the next generation paging source. Closes cashapp#2434.
I've run into the same problem. It's caused by the special logic in It's a pretty easy repro, actually. For example, with Compose LazyPagingItems, a constant row count of 2, a large pageSize of 100, and an even larger initialLoadSize of 150, here's a debug trace on Line 40 in 4c1ef92
The trace shows execution state from a few consecutive query invalidations before the exception ends up getting triggered. There are no changes to the table, all this happens purely via invalidations:
The state on the final line triggers the exception. The prior line already shows the mess, and can cause duplicate key errors in the UI, with 3 rows being displayed instead of 2. It's easy to walk through the code with this info to pinpoint the issue. It seems to me that the code and tests are based on a false understanding of how prevKey and Prepend work. My understanding is that prevKey is intended to be the key right before the first key returned in the LoadResult, not the key minus current page offset that the current implementation seems to use. A Prepend load needs to be fulfilled by taking its key and going backwards from it. The key of a Prepend is not intended to be offset already, a Prepend reverses the paging direction. I don't mean reversing the row order of the LoadResult, just reversing the offset direction. |
Also, I've found that short of some complex custom strategy, returning |
i got the same error when testing the code bellow
E/AndroidRuntime: FATAL EXCEPTION: main
|
It's possible that on a paging source that's not in the initial generation, we fail with an `IndexOutOfBoundsException`. This is caused when the underlying data source undergoes a delete, which then invalidates the paging source, which then calls `getRefreshKey`. In the event that the the refresh key is the very last index of the previous paging source, we would fail with the above exception because that index does not exist in the next generation paging source. Closes cashapp#2434.
This should be resolved by #3396 which is in 2.0.0-alpha04. |
@veyndan Is it possible to release this fix with 1.5.* ? Facing this issue when using |
@AlecStrong Thoughts? I suppose it depends on how soon 2.0.0 will be out. |
No target date, we're not going to target bugfixes for the 1.5.* branches in general, only compatibility fixes. If you need the bugfix I'd recommend switching to the alpha. You could switch to the alpha for only the paging artifact potentially, you would have to write a shim between the 1.5 runtime and 2.x runtime but i dont think it would be impossible |
Unfortunately it crashes due to a sqldelight bug. Must upgrade to 2.0.0 alpha cashapp/sqldelight#2434
Unfortunately it crashes due to a sqldelight bug. Must upgrade to 2.0.0 alpha cashapp/sqldelight#2434
- Uses RemoteMediator to page the movie list from the database while fetching new data from the network. - Upgrades SQLDelight to 2.0.0-alpha05 to fix cashapp/sqldelight#2434
SQLDelight version: 1.5.0
Application OS: Android
I am loading a database from the network in pages and using the android-paging3 extension to feed a RecyclerView with the data from the database. On occasion I am seeing the following exception and crash. I believe it does appear to be some kind of timing issue but I cannot tell how/why it is happening? I was hoping that someone could help with some advice or tips on what to look at as far as loading page size and PagingConfig (page size, prefetchsize, etc...) where something is off and creating this exception.
Thanks for the help!
The text was updated successfully, but these errors were encountered: