{"action":"created","issue":{"url":"https://api.github.com/repos/pouchdb/pouchdb/issues/5606","repository_url":"https://api.github.com/repos/pouchdb/pouchdb","labels_url":"https://api.github.com/repos/pouchdb/pouchdb/issues/5606/labels{/name}","comments_url":"https://api.github.com/repos/pouchdb/pouchdb/issues/5606/comments","events_url":"https://api.github.com/repos/pouchdb/pouchdb/issues/5606/events","html_url":"https://github.com/pouchdb/pouchdb/issues/5606","id":173684369,"number":5606,"title":"Unexpected 409 Conflict while using latest winning _rev","user":{"login":"dharders","id":16676192,"avatar_url":"https://avatars.githubusercontent.com/u/16676192?v=3","gravatar_id":"","url":"https://api.github.com/users/dharders","html_url":"https://github.com/dharders","followers_url":"https://api.github.com/users/dharders/followers","following_url":"https://api.github.com/users/dharders/following{/other_user}","gists_url":"https://api.github.com/users/dharders/gists{/gist_id}","starred_url":"https://api.github.com/users/dharders/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dharders/subscriptions","organizations_url":"https://api.github.com/users/dharders/orgs","repos_url":"https://api.github.com/users/dharders/repos","events_url":"https://api.github.com/users/dharders/events{/privacy}","received_events_url":"https://api.github.com/users/dharders/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-08-29T02:21:45Z","updated_at":"2016-08-29T04:16:12Z","closed_at":null,"body":"<!--\r\n     Hello! 👋\r\n     Thank you for opening an issue on PouchDB.\r\n     This template is optional, but it may help us fix your issue faster.\r\n-->\r\n\r\n### Environment (Node.js/browser/hybrid app/etc.)\r\n\r\nBrowser\r\n\r\n### Browser/platform (Chrome/FF/Safari/Edge/iOS/Android/etc.)\r\n\r\nChrome\r\n\r\n### Adapter (IndexedDB/WebSQL/LevelDB/etc.)\r\n\r\nWebSQL\r\n\r\n### Server (CouchDB/Cloudant/Couchbase/PouchDB Server/etc.)\r\n\r\nCouchDB 2.0-RC4\r\n\r\n### Please describe your issue. Test cases (e.g. JSBin) are very helpful!\r\n\r\nPouch 5.4.5\r\n\r\nI have always assumed with PouchDB that if I first `db.get()` then use that returned document  to `db.put` back into the database (after modifying it) was a safe operation, as it **should already contain the latest winning revision**. \r\n\r\n```javascript\r\nlocalDB.get('docXYZ').then((doc) => {\r\n   doc[\"deletedDateTime\"] = Date.now();\r\n   doc[\"_deleted\"] = true;\r\n   return localDB.put(doc);\r\n}).then((doc) => {\r\n   console.log(doc);\r\n}).catch((err) => console.log(err));\r\n```\r\n\r\nBut recently I found a few documents in my database that returned **409 Conflicts** when running the code above (with different doc._id's of course). **Note:** I do not have live replication running, so no-one else could be updating the same document simultaneously\r\n\r\nRunning `localDB.get('docXYZ', {`**`conflicts: true`**`})` showed that there were no existing conflicts (i.e. `_conflicts` array was not present).\r\n\r\nAfter much head-scratching I found after running `localDB.get('docXYZ', {`**`open_revs: 'all'`**`})` it returned an array of length 2. The first (position 0) was showing a different __higher__ `_rev: 7xxx` number than that was returned by the standard `localDB.get` with no options. The second (position 1) was showing the earlier `_rev: 4-xxx`.\r\n\r\nUsing the __higher__ `_rev: 7xxx` with `localDB.put()` yielded the same 409 conflict message.\r\n\r\n- Is this normal PouchDB behaviour and I've just made wrong assumptions ?\r\n- Could it be that this is the result of a mongrelled db that has been replicated from CouchDB 1.6 -> 2 ->1.6 -> 2 ?\r\n- Can I add a new field at the same time as setting `_deleted: true` ?\r\n- Could anything else be causing this 409 ?\r\n\r\nI know you'd like an easy way to reproduce this error, but I've found it quite difficult, although my db is currently in this state now and could be privately shared if req'd.\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/pouchdb/pouchdb/issues/comments/243028756","html_url":"https://github.com/pouchdb/pouchdb/issues/5606#issuecomment-243028756","issue_url":"https://api.github.com/repos/pouchdb/pouchdb/issues/5606","id":243028756,"user":{"login":"dharders","id":16676192,"avatar_url":"https://avatars.githubusercontent.com/u/16676192?v=3","gravatar_id":"","url":"https://api.github.com/users/dharders","html_url":"https://github.com/dharders","followers_url":"https://api.github.com/users/dharders/followers","following_url":"https://api.github.com/users/dharders/following{/other_user}","gists_url":"https://api.github.com/users/dharders/gists{/gist_id}","starred_url":"https://api.github.com/users/dharders/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dharders/subscriptions","organizations_url":"https://api.github.com/users/dharders/orgs","repos_url":"https://api.github.com/users/dharders/repos","events_url":"https://api.github.com/users/dharders/events{/privacy}","received_events_url":"https://api.github.com/users/dharders/received_events","type":"User","site_admin":false},"created_at":"2016-08-29T04:16:12Z","updated_at":"2016-08-29T04:16:12Z","body":"> Can I add a new field at the same time as setting _deleted: true ?\r\n\r\nAfter a bit of experimenting, it seems that the answer is that you shouldn't. It can work, but doesn't always (as in my case).\r\n\r\nIf I update my doc in two steps, it works. Strange. i.e.\r\n\r\n```javascript\r\nlocalDB.get('docXYZ').then((doc) => {\r\n   doc[\"deletedDateTime\"] = Date.now();   \r\n   return localDB.put(doc);\r\n}).then((doc) => {\r\n  return localDB.get('docXYZ');\r\n}).then((doc) => {\r\n   doc[\"_deleted\"] = true;\r\n   return localDB.put(doc);\r\n}).then((doc) => {\r\n   console.log(doc);\r\n}).catch((err) => console.log(err));\r\n```\r\n\r\nThis code succeeds without any 409's. I guess I could combine the extra `get()` and `put()` into a `remove()` to clean it up a little.\r\n\r\n**Before I close this**, can any PouchDB gurus confirm that you shouldn't add anything else to the document when deleting via the `_delete: true` method ? \r\n\r\nIf yes, I'll just have to update my codebase on my original (incorrect?) assumption that you could."}}
{"actor":{"display_login":"dharders"}}