CCExtractor / CCExtractor/taskwarrior-flutter

Data Inconsistency When Editing Task (Missing Transaction)

オープン
#643 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
bug
主要言語
Dart
スター
244
フォーク
179
平均マージ
12時間 42分
マージ済み PR(30日)
2

説明

### Describe your issue

When editing a task using saveEditedTaskInDB() in task_database.dart, the task details and associated tags are updated using separate database operations without a single transaction.

This can lead to data inconsistency if the app crashes or an error occurs between the task update and tag update operations.

As a result:

Task fields (description, project, etc.) may update successfully
Tags may remain stale or partially updated

This violates atomicity and can reduce user trust in data integrity.****

### Steps to reproduce

Open the app and navigate to any existing task
Edit the task (change description and tags)
Trigger a failure between operations (e.g., force close app after task update but before tag update)
Restart the app and fetch the task

### What was the expected result?

_No response_

### Put here any screenshots or videos (optional)

_No response_

### How can we contact you (optional)

Task update and tag update should be atomic
Either both updates succeed, or none are applied
No partial or inconsistent state should exist
Actual behavior
Task is updated successfully
Tags remain unchanged or partially updated
Database enters inconsistent state
Root cause

In saveEditedTaskInDB():

await _database!.update('Tasks', {...});

if (newTags.isNotEmpty) {
TaskForC? task = await getTaskByUuid(uuid);
await setTagsForTask(uuid, task?.id ?? 0, newTags.toList());
}
Multiple DB operations are executed outside a transaction
setTagsForTask() internally uses a separate transaction
getTaskByUuid() reads using _database, not transaction context
Proposed fix

Wrap all operations in a single database transaction and avoid nested transactions:

await _database!.transaction((txn) async {
await txn.update(...);

final taskMaps = await txn.query(...);
final taskId = taskMaps.first['id'];

await txn.delete(...);

for (String tag in newTags) {
await txn.insert(...);
}
});
**Additional notes**
Avoid calling _database inside a transaction → use txn
Avoid nested transactions (setTagsForTask() should accept txn)
Consider enforcing PRAGMA foreign_keys = ON for relational integrity
**Impact**
Data inconsistency
Partial updates
Poor user experience
Suggested priority

High – affects core data integrity

### Would you like to work on this issue?

Yes

### By submitting this issue, I have confirmed that:

- [x] I have starred the repo ⭐ and watched 👀 it on GitHub and followed the contribution guidelines.

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

task_database.dart の saveEditedTaskInDB() から始め、現在のデータベース境界を理解するために setTagsForTask() と getTaskByUuid() を調べます。タスクのフィールドとタグを含む編集を、操作間の中断も含めて再現します。タスクとタグの変更が両方とも成功するか、どちらも永続化されず、トランザクション内にネストされたデータベースアクセスやトランザクション外のデータベースアクセスがない状態になれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
dart, flutter
領域
databases, mobile-dev
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
52/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。