Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

Deleted document causes crash when using getDocumentsWithIDs #67

Open
lambmj opened this issue Apr 24, 2013 · 3 comments
Open

Deleted document causes crash when using getDocumentsWithIDs #67

lambmj opened this issue Apr 24, 2013 · 3 comments

Comments

@lambmj
Copy link
Contributor

lambmj commented Apr 24, 2013

My code:

CouchQuery *query = [self.database getDocumentsWithIDs:@[@"E12906BA-3BCD-4E1D-8297-20917C85BC1D"]];
CouchQueryRow *row = [query.rows nextRow];
NSLog(@"row = %@", row); 

crashes on the last line with this error when retrieving a deleted document from CouchDB:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull objectForKey:]: unrecognized selector sent to instance 

The cause appears to be that CouchQueryRow doesn't check to see if document is null before attempting to retrieve properties from it in this (and other) code in CouchQuery.m

- (NSString*) documentID {
    NSString* docID = [[_result objectForKey: @"doc"] objectForKey: @"_id"];
    if (!docID)
        docID = [_result objectForKey: @"id"];
    return docID;
}

The raw query retrieves rows for deleted documents even if include_deleted is false:

curl -X POST 'http://user:password@couchdemo:5984/channel-c/_all_docs?include_docs=true&update_seq=true&include_deleted=false' -H 'Content-Type: application/json' -d '{ "keys":["E12906BA-3BCD-4E1D-8297-20917C85BC1D"]}'
{"total_rows":48,"update_seq":2995,"offset":0,"rows":[
{"id":"E12906BA-3BCD-4E1D-8297-20917C85BC1D","key":"E12906BA-3BCD-4E1D-8297-20917C85BC1D","value":{"rev":"14-816a350e91526ad90043b11baebe78eb","deleted":true},"doc":null}
]}

It's not clear to me if the best fix is to patch the calls and add a deleted property to CouchQueryRow or if CouchQuery should not return this row in the first place.

@snej
Copy link
Contributor

snej commented Apr 24, 2013

Is this talking to a CouchDB server, not TouchDB?

The JSON returned by the query is weird — I didn't think the doc property could be null.

@snej
Copy link
Contributor

snej commented Apr 24, 2013

Also, I don't think I've ever heard of an include_deleted query param. It's not described anywhere in the CouchDB wiki.

@lambmj
Copy link
Contributor Author

lambmj commented Apr 24, 2013

Yes, it's a CouchDB 1.2.1 server. I saw the include_deleted in a post on Stack Overflow. It didn't matter -- I got the same results either way

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants