| 1 |
From: ryneeverett <[email protected]> |
| 2 |
Date: Thu, 31 Dec 2020 19:48:58 +0000 |
| 3 |
Subject: Fix duplicate completed task exception. |
| 4 |
|
| 5 |
This implementation aims to be a more performant alternative to #796 by |
| 6 |
avoiding an extra taskwarrior query on each loop. |
| 7 |
--- |
| 8 |
bugwarrior/db.py | 17 ++++++++++++++--- |
| 9 |
1 file changed, 14 insertions(+), 3 deletions(-) |
| 10 |
|
| 11 |
diff --git a/bugwarrior/db.py b/bugwarrior/db.py |
| 12 |
index 6ddc2ab..fc1a1d6 100644 |
| 13 |
--- a/bugwarrior/db.py |
| 14 |
+++ b/bugwarrior/db.py |
| 15 |
@@ -182,9 +182,20 @@ def find_taskwarrior_uuid(tw, keys, issue): |
| 16 |
('status', 'completed') |
| 17 |
], |
| 18 |
}) |
| 19 |
- possibilities = possibilities | set([ |
| 20 |
- task['uuid'] for task in results |
| 21 |
- ]) |
| 22 |
+ new_possibilities = set([task['uuid'] for task in results]) |
| 23 |
+ # Previous versions of bugwarrior did not allow for reopening |
| 24 |
+ # completed tasks, so there could be multiple completed tasks |
| 25 |
+ # for the same issue if it was closed and reopened before that. |
| 26 |
+ if len(new_possibilities) > 1 and all( |
| 27 |
+ r['status'] == 'completed' for r in results): |
| 28 |
+ for r in results[1:]: |
| 29 |
+ for k in key_list: |
| 30 |
+ if r[k] != results[0][k]: |
| 31 |
+ break |
| 32 |
+ else: |
| 33 |
+ # All results are completed duplicates. |
| 34 |
+ new_possibilities = set([new_possibilities.pop()]) |
| 35 |
+ possibilities = possibilities | new_possibilities |
| 36 |
|
| 37 |
if len(possibilities) == 1: |
| 38 |
return possibilities.pop() |