bitfireAT / icsx5

ICSx⁵ is an Android app to subscribe to remote or local iCalendar files (like time tables of your school/university or event files of your sports team).
https://icsx5.bitfire.at
GNU General Public License v3.0
180 stars 9 forks source link

"Couldn't create calendar" when adding a subscription #116

Closed rfc2822 closed 1 year ago

rfc2822 commented 1 year ago

Somehow I managed to get this exception. The steps were:

  1. I had already a subscription (US holidays).
  2. Add a new subscription (Austrian holidays).
  3. Work through the "Add subscription" dialogs. When finally clicking on the last checkmark, it fails with a Toast and this exception in adb logs:
E/icsx5: Couldn't create calendar
    android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: subscriptions.id (code 1555 SQLITE_CONSTRAINT_PRIMARYKEY)
        at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method)
        at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:940)
        at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:790)
        at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:89)
        at androidx.sqlite.db.framework.FrameworkSQLiteStatement.executeInsert(FrameworkSQLiteStatement.kt:42)
        at androidx.room.EntityInsertionAdapter.insertAndReturnIdsList(EntityInsertionAdapter.kt:202)
        at at.bitfire.icsdroid.db.dao.SubscriptionsDao_Impl.add(SubscriptionsDao_Impl.java:210)
        at at.bitfire.icsdroid.ui.AddCalendarDetailsFragment$SubscriptionModel$create$1$ids$1.invokeSuspend(AddCalendarDetailsFragment.kt:117)
        at at.bitfire.icsdroid.ui.AddCalendarDetailsFragment$SubscriptionModel$create$1$ids$1.invoke(Unknown Source:8)
        at at.bitfire.icsdroid.ui.AddCalendarDetailsFragment$SubscriptionModel$create$1$ids$1.invoke(Unknown Source:4)
        at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:89)
        at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:169)
        at kotlinx.coroutines.BuildersKt.withContext(Unknown Source:1)
        at at.bitfire.icsdroid.ui.AddCalendarDetailsFragment$SubscriptionModel$create$1.invokeSuspend(AddCalendarDetailsFragment.kt:117)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
        at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
ArnyminerZ commented 1 year ago

Seems to be quite a stupid mistake, I forgot to add autoGenerate = true for the primary key.

Since default is 0L, it was trying to add multiple subscriptions with the same id.