I have a strange issue with my Room database. I am...
# room
b
I have a strange issue with my Room database. I am using
Room 2.7.0-alpha11
in my KMP project. I am reading my database data with the next query:
Copy code
@Query("SELECT * FROM ${Event.TABLE_NAME}")
    fun getAllEvents(): Flow<List<EventEntity>>
And I have a Query for removing the item like this:
Copy code
@Query("DELETE FROM ${Event.TABLE_NAME} WHERE ${Event.COLUMN_ID} == :id")
    suspend fun removeById(id: String)
In a case when removeById is called as a single method without transaction, item gets successfully removed and query that reads all items from database return update List of Event items. But if removal is done within transaction, the item is also successfully removed, but it is not detected by Flow. So next block is not working for me:
Copy code
database.useWriterConnection {
    it.immediateTransaction {
        eventEntity = database.getEventDao().getEventById(id)
        database.getEventDao().removeById(id)
        database.getAttendeeDao().removeByEventId(id)
    }
}
What could be the reason for that? Any ideas? Maybe I am missing some Room based annotations on my Dao methods?
d
This is a known issue, please see: https://issuetracker.google.com/340606803#comment2 TL;DR: You'll need to call
invalidationTracker.refreshAsync()
after you are done with the connection to trigger invalidation since Room doesn't know well what was done during the transaction (could have been all read operations).
🙌 1
b
Thank you @danysantiago. That is exactly my use case.