summaryrefslogtreecommitdiff
path: root/common/src/leap/soledad
diff options
context:
space:
mode:
Diffstat (limited to 'common/src/leap/soledad')
-rw-r--r--common/src/leap/soledad/common/couch/__init__.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/common/src/leap/soledad/common/couch/__init__.py b/common/src/leap/soledad/common/couch/__init__.py
index ca0c2855..ba3192a4 100644
--- a/common/src/leap/soledad/common/couch/__init__.py
+++ b/common/src/leap/soledad/common/couch/__init__.py
@@ -714,7 +714,18 @@ class CouchDatabase(object):
if not self.batching:
buf = StringIO()
envelope = MultipartWriter(buf)
- envelope.add('application/json', json.dumps(couch_doc))
+ # the order in which attachments are described inside the
+ # serialization of the couch document must match the order in which
+ # they are actually written in the multipart structure. Because of
+ # that, we use `sorted_keys=True` in the json serialization (so
+ # "u1db_conflicts" comes before "u1db_content" on the couch
+ # document attachments description), and also reverse the order of
+ # the parts before writing them, so the "conflict" part is written
+ # before the "content" part.
+ envelope.add(
+ 'application/json',
+ json.dumps(couch_doc, sort_keys=True))
+ parts.reverse()
for part in parts:
envelope.add('application/octet-stream', part)
envelope.close()