{"action":"created","issue":{"url":"https://api.github.com/repos/couchbase/couchbase-lite-java-core/issues/677","labels_url":"https://api.github.com/repos/couchbase/couchbase-lite-java-core/issues/677/labels{/name}","comments_url":"https://api.github.com/repos/couchbase/couchbase-lite-java-core/issues/677/comments","events_url":"https://api.github.com/repos/couchbase/couchbase-lite-java-core/issues/677/events","html_url":"https://github.com/couchbase/couchbase-lite-java-core/issues/677","id":95139687,"number":677,"title":"Pulling attachments fail if document got a deleted revision in history","user":{"login":"saubaer","id":498915,"avatar_url":"https://avatars.githubusercontent.com/u/498915?v=3","gravatar_id":"","url":"https://api.github.com/users/saubaer","html_url":"https://github.com/saubaer","followers_url":"https://api.github.com/users/saubaer/followers","following_url":"https://api.github.com/users/saubaer/following{/other_user}","gists_url":"https://api.github.com/users/saubaer/gists{/gist_id}","starred_url":"https://api.github.com/users/saubaer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/saubaer/subscriptions","organizations_url":"https://api.github.com/users/saubaer/orgs","repos_url":"https://api.github.com/users/saubaer/repos","events_url":"https://api.github.com/users/saubaer/events{/privacy}","received_events_url":"https://api.github.com/users/saubaer/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/couchbase/couchbase-lite-java-core/labels/bug","name":"bug","color":"e11d21"},{"url":"https://api.github.com/repos/couchbase/couchbase-lite-java-core/labels/review","name":"review","color":"ededed"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/couchbase/couchbase-lite-java-core/milestones/6","html_url":"https://github.com/couchbase/couchbase-lite-java-core/milestones/1.2.0","labels_url":"https://api.github.com/repos/couchbase/couchbase-lite-java-core/milestones/6/labels","id":771954,"number":6,"title":"1.2.0","description":"","creator":{"login":"jessliu","id":4998909,"avatar_url":"https://avatars.githubusercontent.com/u/4998909?v=3","gravatar_id":"","url":"https://api.github.com/users/jessliu","html_url":"https://github.com/jessliu","followers_url":"https://api.github.com/users/jessliu/followers","following_url":"https://api.github.com/users/jessliu/following{/other_user}","gists_url":"https://api.github.com/users/jessliu/gists{/gist_id}","starred_url":"https://api.github.com/users/jessliu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jessliu/subscriptions","organizations_url":"https://api.github.com/users/jessliu/orgs","repos_url":"https://api.github.com/users/jessliu/repos","events_url":"https://api.github.com/users/jessliu/events{/privacy}","received_events_url":"https://api.github.com/users/jessliu/received_events","type":"User","site_admin":false},"open_issues":30,"closed_issues":11,"state":"open","created_at":"2014-08-29T17:31:06Z","updated_at":"2015-07-28T00:43:07Z","due_on":null,"closed_at":null},"comments":5,"created_at":"2015-07-15T09:01:37Z","updated_at":"2015-07-28T01:32:12Z","closed_at":null,"body":"To reproduce:\r\n\r\ncreate a pull replication to a couchdb (1.6.1 in my case)\r\n\r\n1. insert a document containing an attachement (rev: 1-x)\r\n2. pull replicate\r\n3. delete the document (rev: 2-x)\r\n4. pull replicate\r\n5. insert the document again, containing the same attachment.(rev: 3-x)\r\n6. pull replicate\r\n\r\nThe replication from step 6 will query couchdb with atts_since=2-x and couchdb will answer with an _attachment stub containing revpos: 1\r\n\r\nCBL inserts the revision (3-x) into the revs table and tries to get the attachment from the parent sequence (2-x).\r\nhttps://github.com/couchbase/couchbase-lite-java-core/blob/master/src/main/java/com/couchbase/lite/Database.java#L2967\r\n\r\nThis fails, since the deleted revision doesn't contain the attachment.\r\n\r\nWhen I take a look at the attachments table of sqlite I find the attachment for rev 1-x is there.\r\n\r\nI'm not sure what the best way would be to fix this.\r\nMaybe an additional step to find the attachment by the given revpos, somewhere around here: https://github.com/couchbase/couchbase-lite-java-core/blob/master/src/main/java/com/couchbase/lite/Database.java#L4471-L4478?"},"comment":{"url":"https://api.github.com/repos/couchbase/couchbase-lite-java-core/issues/comments/125401208","html_url":"https://github.com/couchbase/couchbase-lite-java-core/issues/677#issuecomment-125401208","issue_url":"https://api.github.com/repos/couchbase/couchbase-lite-java-core/issues/677","id":125401208,"user":{"login":"hideki","id":15889,"avatar_url":"https://avatars.githubusercontent.com/u/15889?v=3","gravatar_id":"","url":"https://api.github.com/users/hideki","html_url":"https://github.com/hideki","followers_url":"https://api.github.com/users/hideki/followers","following_url":"https://api.github.com/users/hideki/following{/other_user}","gists_url":"https://api.github.com/users/hideki/gists{/gist_id}","starred_url":"https://api.github.com/users/hideki/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hideki/subscriptions","organizations_url":"https://api.github.com/users/hideki/orgs","repos_url":"https://api.github.com/users/hideki/repos","events_url":"https://api.github.com/users/hideki/events{/privacy}","received_events_url":"https://api.github.com/users/hideki/received_events","type":"User","site_admin":false},"created_at":"2015-07-28T01:32:12Z","updated_at":"2015-07-28T01:32:12Z","body":"Hi @saubaer,\r\n\r\nSorry for late reply. We recently update database architecture to remove \"attachments\" table from SQLite database. For this change, we updated many attachment related codes, and it made your PR not merge-able. \r\n\r\nI tested if master branch code works well with error scenario you wrote in the ticket (https://github.com/couchbase/couchbase-lite-java-core/issues/677#issuecomment-122527475). But I could not reproduce it. Do you have a chance to test with latest master branch?\r\n\r\nThanks,\r\nHideki"}}