Resolve conflicts#
A sync stores a conflict where the server changed an event you edited too, and carries on with the others. The event waits until you resolve it, and the next sync sends the result. In the examples below, another client moved the meeting while your application renamed it.
Resolve one conflict#
from calendaring_sync import KeepLocal, RecordState
for record in replica.records("work", states=frozenset({RecordState.CONFLICT})):
replica.resolve(record, KeepLocal())
adapter.sync()
resolve() takes the record you read and a Resolution. If the conflict changed since you read it, it raises StaleConflictError, so you never decide on news you haven’t seen. Each class in calendaring_sync.objects.resolution says what it does.
Resolve every conflict with a function#
from calendaring_sync import ConflictKind, KeepServer, Merge
def resolver(record):
conflict = record.conflict
if conflict.kind is ConflictKind.BOTH_CHANGED:
merged = conflict.remote_content + b" / " + record.edit.content
return Merge(merged, adapter.edit_fields(merged))
if conflict.kind is ConflictKind.REMOVED_REMOTELY:
return KeepServer()
return None
replica.resolve_conflicts(resolver)
adapter.sync()
resolve_conflicts() calls your function with each open conflict, and None leaves one open. It returns a ResolvedConflicts saying which conflicts it resolved, left open, or found changed while your function ran. A Merge needs the fields the adapter reads from content, which edit_fields() returns. Record.conflict holds the server’s copy, and ConflictKind says what each side did.