Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions syncall/caldav/caldav_side.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ def set_(key: str, val: Any): # noqa: ANN401
set_(key, vText(value))
if key == "categories":
set_(key, vCategory([vText(cat) for cat in value]))
if key == SYNCALL_TW_WAITING:
set_(key, vText(value))

todo.save()

Expand Down
4 changes: 4 additions & 0 deletions syncall/caldav/caldav_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ def _convert_one(name: str) -> str:
for name in ["description", "summary"]:
todo_item[name] = _convert_one(name)
todo_item["uuid"] = _convert_one("x-syncall-tw-uuid")
# Read the waiting flag back too: the TW -> CalDAV conversion always sets it, so without it a
# changed item never compares equal to its counterpart and is updated again on every run.
if vtodo.get("x-syncall-tw-waiting") is not None:
todo_item["x-syncall-tw-waiting"] = str(vtodo.get("x-syncall-tw-waiting"))

for date_field in ("due", "created", "completed", "last-modified"):
if vtodo.get(date_field):
Expand Down
4 changes: 4 additions & 0 deletions syncall/taskwarrior/taskwarrior_side.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ def items_are_identical(
tw_duration_key,
]
if k not in ignore_keys
# Fields that the other side may not carry (e.g. CalDAV has no "scheduled" or
# duration) only count when both items have them; otherwise such a task never
# compares equal and is updated on every run.
and not (k in ("scheduled", tw_duration_key) and ((k in item1) != (k in item2)))
]

# special care for the annotations key
Expand Down
29 changes: 29 additions & 0 deletions tests/test_tw_caldav_stable_sync.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""A task that was changed once must compare equal to its counterpart afterwards,
otherwise it is updated again on every run, alternating sides."""

import datetime

from icalendar import Todo
from syncall.caldav.caldav_utils import map_ics_to_item
from syncall.taskwarrior.taskwarrior_side import TaskWarriorSide
from syncall.tw_caldav_utils import SYNCALL_TW_WAITING, convert_tw_to_caldav


def test_waiting_flag_is_read_back_from_caldav():
tw_task = {"description": "t", "status": "pending", "uuid": "3925e236-3b27-4888-b41c-8c53610d722b"}
sent = convert_tw_to_caldav(tw_task)
todo = Todo()
todo.add("uid", "x")
todo.add("summary", "t")
todo.add("status", "NEEDS-ACTION")
todo.add(SYNCALL_TW_WAITING, sent[SYNCALL_TW_WAITING])
assert map_ics_to_item(todo)[SYNCALL_TW_WAITING] == sent[SYNCALL_TW_WAITING]


def test_scheduled_only_on_one_side_is_not_a_difference():
due = datetime.datetime(2026, 11, 30, 23, tzinfo=datetime.timezone.utc)
task = {"description": "t", "status": "pending", "due": due, "uuid": "u",
"scheduled": due - datetime.timedelta(days=1)}
from_caldav = {k: v for k, v in task.items() if k != "scheduled"}
assert TaskWarriorSide.items_are_identical(task, from_caldav)
assert not TaskWarriorSide.items_are_identical(task, {**task, "scheduled": due})