Yes, this is what seems to be happening, I can't see it from the stack 
trace but I think this is actually coming from a CBLModel that has been 
deleted, and while the model instance is still around the document is gone. 
The assert doesn't hit in production code so this makes sense, I'll add a 
document.documentID check to the beginning of these methods. Thanks!


On Tuesday, May 20, 2014 6:53:07 AM UTC-4, Ragu Vijaykumar wrote:
>
> From what I see, documentID is a readonly property of CBLDocument, and it 
> doesn't seem to ever be manipulated in the class. It is passed in on 
> initialization, so is there any chance that you created a CBLDocument with 
> a nil docID?
>
> CBLDocuments are cached, so perhaps you are getting a zombie CBLDocument 
> from a document that has been evicted from the cache? You sure there is no 
> way to for this method to be called with a dealloc'd CBLDocument that is 
> still floating around?
>
> On Sunday, May 18, 2014 8:50:38 AM UTC-7, Pascal wrote:
>>
>> I have the following class method, which returns a CBLQuery scoped to a 
>> given document. It does that by emitting a document-id first, ordering by 
>> that key and setting start- and stop-keys.
>>
>> Now I have received a handful of crash reports from Crashlytics where 
>> this method crashes when I set the start key to a nil document ID. I cannot 
>> reproduce the crash as the method should only ever be called for a document 
>> that has been stored in the database already. So before I go nuts trying to 
>> figure out when this happens, could it be that Couchbase unsets the 
>> document's `documentID` in certain scenarios? Thanks!
>>
>> + (CBLQuery *)resultsByDateForDocument:(CBLDocument *)document
>>
>> {
>>
>> NSParameterAssert(document);
>>
>>  CBLView* view = [document.database viewNamed:@"patientResultsByDate"];
>>
>> if (!view.mapBlock) {
>>
>> [view setMapBlock:MAPBLOCK({
>>
>> if ([@"result" isEqualToString:doc[@"type"]]) {
>>
>> emit(@[doc[@"patient"], doc[@"date"] ?: [[NSDate new] 
>> med_isoRepresentation]], doc[@"_id"]);
>>
>> }
>>
>> }) version: @"2"];
>>
>> }
>>
>>  NSString *docID = document.documentID; // if this is nil...
>>
>> CBLQuery *query = [view createQuery];
>>
>> query.descending = YES;
>>
>> query.startKey = @[docID, @{}]; // ...this crashes
>>
>> query.endKey = @[docID];
>>
>>  return query;
>>
>> }
>>
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mobile-couchbase/9b4ece5a-f90e-48a4-aee5-bfa45e7e985f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to