-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Room. Incorrect behavior of methods with @Upsert annotation. #8469
Comments
This happens for me as well, but in my case the test fails only when running it on Windows machine. It passes for my colleagues running the exact same test on MacOS. |
I don't why does it differ between different operating systems but one possible solution (from the robolectric team) can be to not completely replace the exception messages with their own one.
So the updated exception message still contains the original message as well (with the proper error code and |
Hi @BekhtaTaras, Unfortunately, on Windows, the Android SQLite database is powered by a legacy version of sqlite4java, and on Mac+Linux it is using real native Android SQLite code. I wish Windows had feature parity, but unfortunately we haven't been able to get that prioritized due to other projects and initiatives. Similarly, none of the current Robolectric maintainers use Windows. It is technically possible to support Android SQLite in Windows, it just requires a potentially non-trivial amount of work and investigation. If you (or someone else) would like to contribute to Windows support, we'd be happy to provide assistance and guidance. |
I'm having the exact same issue, on windows... @hoisie I understand... Would it be too bad to implement the fix/workaround proposed by @BekhtaTaras ?
Or it would bring other unwanted side effects? |
Making error messages consistent sounds good to me. A lot of these exceptions are generated from the Android SQLite C++ bindings, which are not run on Windows (they use the sqlite4java swig bindings). However, we can probably just shim the exceptions in Java code. If libraries like room check for specific Android SQLite exceptions, we should probably make them consistent. |
Thanks @hoisie ! So, you think we could expect some sort of fix on an upcoming release? |
@ampeixoto I'll add this issue to my queue, but I cannot really guarantee anything. If this issue is important to you, I would definitely recommend sending a PR to fix it, and I would be happy to review it. |
For #8469 PiperOrigin-RevId: 582331582
Previously, in the legacy SQLite mode, all exceptions thrown by SQLite were wrapped in an arbitrary RuntimeExceptions. This is not consistent with real Android, which always throws exceptions of type android.database.sqlite.SQLiteException (including subclasses). This has impact on data layer libraries such as Room that explicitly catch Android SQLiteExceptions in order to execute error callback logic. For #8469 PiperOrigin-RevId: 582331582
Previously, in the legacy SQLite mode, all exceptions thrown by SQLite were wrapped in an arbitrary RuntimeExceptions. This is not consistent with real Android, which always throws exceptions of type android.database.sqlite.SQLiteException (including subclasses). This has impact on data layer libraries such as Room that explicitly catch Android SQLiteExceptions in order to execute error callback logic. For #8469 PiperOrigin-RevId: 582557176
This should be fixed in the latest 4.12-SNAPSHOT, I would give that a try. |
Thank you @hoisie I will try that later today |
I have just tried that and now all of my tests pass. Thanks again @hoisie 🥳 |
Description
In Room EntityUpsertionAdapter we can see code:
When code is executed on real device the message variable will be something like this "UNIQUE constraint failed: MeEntity.id (code 1555 SQLITE_CONSTRAINT_PRIMARYKEY[1555])"
When code is executed on Robolectric the message variable will be equal "Cannot execute for last inserted row ID"
As result:
Steps to Reproduce
Robolectric & Android Version
robolectric:4.10.3
android: 12
room: 2.5.1
Link to a public git repo demonstrating the problem:
The text was updated successfully, but these errors were encountered: