Data Inconsistency When Editing Task (Missing Transaction)
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 52/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- dart, flutter
- 领域
- databases, mobile-dev
调研方向
从 task_database.dart 中的 saveEditedTaskInDB() 开始,然后检查 setTagsForTask() 和 getTaskByUuid(),以了解当前的数据库边界。复现一次涉及任务字段和标签的编辑,包括操作之间发生中断的情况。完成标准是任务和标签的更改要么一起成功,要么都不被持久化,并且不存在嵌套的数据库访问或事务外的数据库访问。
由索引模型根据 Issue 内容生成。
描述
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:
- I have starred the repo ⭐ and watched 👀 it on GitHub and followed the contribution guidelines.
- 主要语言
- Dart
- 星标
- 244
- 派生
- 179
- 平均合并
- 12 小时 42 分钟
- 30 天内合并 PR
- 2
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
CCExtractor/taskwarrior-flutter 的其他 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 68/100
CCExtractor/taskwarrior-flutter#639 · 2 条评论 ·
-
bug
难度 1/5 1 小时以内 新手友好度 85/100
-
bug
难度 2/5 1-3 小时 新手友好度 68/100
-
难度 4/5 3-5 天 新手友好度 30/100
CCExtractor/taskwarrior-flutter#647 · 1 个 reaction ·
-
bug
难度 5/5 一周以上 新手友好度 45/100
CCExtractor/taskwarrior-flutter#645 · 1 条评论 ·
查看 CCExtractor/taskwarrior-flutter 的全部 Issue
相似的 Issue
-
bug triage
难度 2/5 1-3 小时 新手友好度 70/100
fluttercommunity/plus_plugins#3979 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
flutter-webrtc/flutter-webrtc#2206 ·
-
from.page-issue
难度 1/5 1 小时以内 新手友好度 85/100
-
enhancement UI: Material
难度 2/5 1-3 小时 新手友好度 75/100
Notsfsssf/pixez-flutter#1360 ·
-
triage
难度 2/5 1-3 小时 新手友好度 70/100