Invalid attachment error while trying to resolve a conflict

15 views
Skip to first unread message

Brendan Duddridge

unread,
Mar 24, 2018, 9:47:49 PM3/24/18
to Couchbase Mobile
Hi,

I'm trying to resolve a conflict in my database and during processing of the conflicts, I try to save the new revision and I get the following error:

19:33:51.584| Database: PUT _id=rec-34444c73468b47e78a82b574c9e1d44f, _rev=38-910e724b542aaa5c6b224bf992e6de09 (allowConflict=1)

19:33:51.584| WARNING: Don't have original attachment for stub '343EBC56-262B-4A23-B2C9-8EA57F5EAC7A~L0~001.jpeg' in {rec-34444c73468b47e78a82b574c9e1d44f #39-00} (missing attachment) {at -[CBLDatabase(Attachments) processAttachmentsForRevision:ancestry:allowStubAttachments:status:]_block_invoke:424}

2018-03-24 19:33:51.584415-0600 Tap Forms 5[28952:19787125] Error saving conflicted document: Error Domain=CBLHTTP Code=400 "Invalid attachment" UserInfo={NSLocalizedFailureReason=Invalid attachment, NSLocalizedDescription=Invalid attachment}


The attachment being saved looks like this:

    "343EBC56-262B-4A23-B2C9-8EA57F5EAC7A~L0~001.jpeg" =     {

        "content_type" = "image/jpeg";

        digest = "sha1-NV3+66TwIEkBkPXfkTHNsWbWeOs=";

        length = 290839;

        revpos = 6;

        stub = 1;

    };



I checked the attachments folder and the image with the blobKey definitely exists. 

According to the source code in CBLDatabase+Attachments.m (424), it's failing because of this block of code:

NSDictionary* parentAttachment = parentAttachments[name];

if (!parentAttachment) {

    Warn(@"Don't have original attachment for stub '%@' in %@ (missing attachment)",

         name, rev);

    *outStatus = kCBLStatusBadAttachment;

    return nil;

}

return parentAttachment;


So it would seem that I don't have a parent attachment.

Is there a way I can manipulate the attachment somehow in order to resolve the conflict?

This is the conflict that's being processed:

2018-03-24 19:33:51.460514-0600 Tap Forms 5[28952:19787125] conflicted doc id: rec-34444c73468b47e78a82b574c9e1d44f

2018-03-24 19:33:51.460766-0600 Tap Forms 5[28952:19787125] conflicts: (

    "CBLSavedRevision[rec-..d44f/38-910e724b542aaa5c6b224bf992e6de09]",

    "CBLSavedRevision[rec-..d44f/6-9f986ed79a5f45a296b807b709c72c31]"

)



So there's quite a big difference between 6 and 38 for the revision numbers. Maybe that has something to do with it?

CBL 1.4.1 on macOS High Sierra btw.

Thanks,

Brendan




Brendan Duddridge

unread,
Sep 12, 2018, 11:46:11 PM9/12/18
to Couchbase Mobile
Hi,

I think this post got lost in the shuffle a long time ago. But I'm seeing this error today and I'm trying to resolve the conflict.

How do I deal with the parentAttachment issue?

What exactly is the parentAttachment? Maybe if I knew that I could figure out a way to solve the problem. 

Thanks,

Brendan

Jens Alfke

unread,
Sep 13, 2018, 12:08:10 PM9/13/18
to mobile-c...@googlegroups.com
I haven’t been inside the 1.x codebase in aeons, but IIRC ‘parentAttachment’ is the attachment Dict in the parent revision of the document. I’m not sure why it’s required to exist at that point; sorry...

—Jens 
--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/90961185-e620-4e44-8c58-635a375bf896%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Privacy Policy | Update Marketing Preferences

Brendan Duddridge

unread,
Sep 13, 2018, 1:50:16 PM9/13/18
to Couchbase Mobile
Thanks for your response Jens.

The reason I got myself into this pickle is because I was attempting to solve a problem where attachments were going missing during a conflict, so I was merging the _attachments dictionaries from the conflicted revisions to prevent attachment file loss. So I think the reason it caused this problem was because one of the attachments in the merged _attachments dictionary didn't exist in the new revisions parent attachments. So it failed to save, even though the attachment .blob file actually did exist on disk. For now I commented out my code that merged attachments and that resolved the conflict. But of course, I would have lost the reference to the attachment.

Maybe 2.0 has more robust attachment support.

Thanks,

Brendan
Reply all
Reply to author
Forward
0 new messages