{"action":"created","issue":{"url":"https://api.github.com/repos/couchbase/couchbase-lite-ios/issues/925","labels_url":"https://api.github.com/repos/couchbase/couchbase-lite-ios/issues/925/labels{/name}","comments_url":"https://api.github.com/repos/couchbase/couchbase-lite-ios/issues/925/comments","events_url":"https://api.github.com/repos/couchbase/couchbase-lite-ios/issues/925/events","html_url":"https://github.com/couchbase/couchbase-lite-ios/issues/925","id":108103594,"number":925,"title":"crash in processing CBLIS changes when document has no type","user":{"login":"mastohhh","id":1760064,"avatar_url":"https://avatars.githubusercontent.com/u/1760064?v=3","gravatar_id":"","url":"https://api.github.com/users/mastohhh","html_url":"https://github.com/mastohhh","followers_url":"https://api.github.com/users/mastohhh/followers","following_url":"https://api.github.com/users/mastohhh/following{/other_user}","gists_url":"https://api.github.com/users/mastohhh/gists{/gist_id}","starred_url":"https://api.github.com/users/mastohhh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mastohhh/subscriptions","organizations_url":"https://api.github.com/users/mastohhh/orgs","repos_url":"https://api.github.com/users/mastohhh/repos","events_url":"https://api.github.com/users/mastohhh/events{/privacy}","received_events_url":"https://api.github.com/users/mastohhh/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/couchbase/couchbase-lite-ios/labels/bug","name":"bug","color":"e11d21"},{"url":"https://api.github.com/repos/couchbase/couchbase-lite-ios/labels/ready","name":"ready","color":"ededed"}],"state":"open","locked":false,"assignee":{"login":"pasin","id":801454,"avatar_url":"https://avatars.githubusercontent.com/u/801454?v=3","gravatar_id":"","url":"https://api.github.com/users/pasin","html_url":"https://github.com/pasin","followers_url":"https://api.github.com/users/pasin/followers","following_url":"https://api.github.com/users/pasin/following{/other_user}","gists_url":"https://api.github.com/users/pasin/gists{/gist_id}","starred_url":"https://api.github.com/users/pasin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pasin/subscriptions","organizations_url":"https://api.github.com/users/pasin/orgs","repos_url":"https://api.github.com/users/pasin/repos","events_url":"https://api.github.com/users/pasin/events{/privacy}","received_events_url":"https://api.github.com/users/pasin/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/couchbase/couchbase-lite-ios/milestones/13","html_url":"https://github.com/couchbase/couchbase-lite-ios/milestones/1.2","labels_url":"https://api.github.com/repos/couchbase/couchbase-lite-ios/milestones/13/labels","id":873603,"number":13,"title":"1.2","description":"Feature release, incorporating ForestDB storage engine","creator":{"login":"snej","id":43241,"avatar_url":"https://avatars.githubusercontent.com/u/43241?v=3","gravatar_id":"","url":"https://api.github.com/users/snej","html_url":"https://github.com/snej","followers_url":"https://api.github.com/users/snej/followers","following_url":"https://api.github.com/users/snej/following{/other_user}","gists_url":"https://api.github.com/users/snej/gists{/gist_id}","starred_url":"https://api.github.com/users/snej/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/snej/subscriptions","organizations_url":"https://api.github.com/users/snej/orgs","repos_url":"https://api.github.com/users/snej/repos","events_url":"https://api.github.com/users/snej/events{/privacy}","received_events_url":"https://api.github.com/users/snej/received_events","type":"User","site_admin":false},"open_issues":18,"closed_issues":65,"state":"open","created_at":"2014-11-20T01:04:30Z","updated_at":"2015-09-28T17:04:54Z","due_on":null,"closed_at":null},"comments":2,"created_at":"2015-09-24T10:36:23Z","updated_at":"2015-09-28T17:13:46Z","closed_at":null,"body":"There's a crash in this method : \r\n\r\n```objc\r\n- (void) processCouchbaseLiteChanges: (NSArray*)changes {\r\n    NSMutableSet* changedEntitites = [NSMutableSet setWithCapacity: changes.count];\r\n    NSMutableArray* deletedObjectIDs = [NSMutableArray array];\r\n    NSMutableArray* updatedObjectIDs = [NSMutableArray array];\r\n\r\n    for (CBLDatabaseChange* change in changes) {\r\n        if (!change.isCurrentRevision) continue;\r\n        if ([change.documentID hasPrefix: @\"CBLIS\"]) continue;\r\n\r\n        CBLDocument* doc = [self.database documentWithID: change.documentID];\r\n        CBLRevision* rev = [doc revisionWithID: change.revisionID];\r\n\r\n        BOOL deleted = rev.isDeletion;\r\n\r\n        NSDictionary* properties = [rev properties];\r\n\r\n        NSString* type = [properties objectForKey: [self documentTypeKey]];\r\n        NSString* reference = change.documentID;\r\n\r\n        NSDictionary *entitiesByName = self.persistentStoreCoordinator.managedObjectModel.entitiesByName;\r\n        NSEntityDescription* entity = entitiesByName[type];\r\n\r\n        // CRASH : type is nil\r\n        NSManagedObjectID* objectID = [self newObjectIDForEntity: entity referenceObject: reference];\r\n\r\n        if (deleted) {\r\n            [deletedObjectIDs addObject: objectID];\r\n        } else {\r\n            [updatedObjectIDs addObject: objectID];\r\n        }\r\n\r\n        [changedEntitites addObject: type];\r\n    }\r\n\r\n    [self informObservingManagedObjectContextsAboutUpdatedIDs: updatedObjectIDs\r\n                                                   deletedIDs: deletedObjectIDs];\r\n}\r\n```\r\n\r\nHere's the properties of the `CBLDocument` : \r\n\r\n```objc\r\n{\r\n    \"_deleted\" = 1;\r\n    \"_id\" = \"E2DDD307-58A1-4542-A36B-A5A15638C5CE-72886-000031E956FD1D7F\";\r\n    \"_rev\" = \"2-f667ec1782f9606f43421cb41a2002f8\";\r\n}\r\n```\r\n\r\nHere's the response of the `sync_gateway` : \r\n\r\n```unix\r\ncurl http://x.x.x.x:4985/database/E2DDD307-58A1-4542-A36B-A5A15638C5CE-72886-000031E956FD1D7F\r\n{\"error\":\"not_found\",\"reason\":\"deleted\"}\r\n```\r\n\r\nMy questions are : \r\n- Why do I receive an object without any `type` ?\r\n- Is it a good solution to avoid the crash by checking `nil`value of this `type` ? Or the problem could be deeper ? (By this way, it doesn't answer why this document has no `type`.)\r\n- Finally, what's the purpose of `changedEntitites` array ?"},"comment":{"url":"https://api.github.com/repos/couchbase/couchbase-lite-ios/issues/comments/143807612","html_url":"https://github.com/couchbase/couchbase-lite-ios/issues/925#issuecomment-143807612","issue_url":"https://api.github.com/repos/couchbase/couchbase-lite-ios/issues/925","id":143807612,"user":{"login":"pasin","id":801454,"avatar_url":"https://avatars.githubusercontent.com/u/801454?v=3","gravatar_id":"","url":"https://api.github.com/users/pasin","html_url":"https://github.com/pasin","followers_url":"https://api.github.com/users/pasin/followers","following_url":"https://api.github.com/users/pasin/following{/other_user}","gists_url":"https://api.github.com/users/pasin/gists{/gist_id}","starred_url":"https://api.github.com/users/pasin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pasin/subscriptions","organizations_url":"https://api.github.com/users/pasin/orgs","repos_url":"https://api.github.com/users/pasin/repos","events_url":"https://api.github.com/users/pasin/events{/privacy}","received_events_url":"https://api.github.com/users/pasin/received_events","type":"User","site_admin":false},"created_at":"2015-09-28T17:13:46Z","updated_at":"2015-09-28T17:13:46Z","body":"@mastohhh I believe you could delete the following 2 lines from -processCouchbaseLiteChanges:.\r\n\r\n```Objective-C\r\nNSMutableSet* changedEntitites = [NSMutableSet setWithCapacity: changes.count];\r\n...\r\n[changedEntitites addObject: type];\r\n```\r\n\r\nHowever I'm still wondering about missing 'type' property from the deleted revision. I would need more time to evaluate to make sure that CBLIS doesn't require 'type' of the deleted revision in the other parts of the code."}}