Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG failed test of pouchdb executing insert -> remove -> insert -> remove #3839

Conversation

nisarpeitang
Copy link

This PR contains:

A failed testcase of PouchDB adapter when executing the routine insert -> remove -> insert -> remove

Describe the problem you have without this PR

The second removal operation will fail due to incorrect revision number. This bug only happens when using PouchDB storage.

RxError (COL19): RxError (COL19):
Document update conflict. When changing a document you must work on the previous revision
Given parameters: {
collection:"mycollection"
id:"test1"
error:{
  "isError": true,
  "status": 409,
  "documentId": "test1",
  "writeRow": {
    "document": {
      "name": "test1",
      "gender": "male",
      "birthyear": 2000,
      "_meta": {
        "lwt": 1654692585166
      },
      "_deleted": true,
      "_attachments": {},
      "_rev": "2-c3801976cb7d9f46ed6227d2b76c5ac8"
    },
    "previous": {
      "name": "test1",
      "gender": "male",
      "birthyear": 2000,
      "_meta": {
        "lwt": 1
      },
      "_deleted": false,
      "_attachments": {},
      "_rev": "1-d29c95b1150dcdbd7e5140fbc5f9be7b"
    }
  },
  "documentInDb": {
    "gender": "male",
    "birthyear": 2000,
    "_attachments": {},
    "_rev": "3-d29c95b1150dcdbd7e5140fbc5f9be7b",
    "name": "test1",
    "_deleted": false,
    "_meta": {
      "lwt": 1654692585158
    }
  }
}
data:{
  "name": "test1",
  "gender": "male",
  "birthyear": 2000,
  "_meta": {
    "lwt": 1
  },
  "_deleted": true,
  "_attachments": {},
  "_rev": "1-d29c95b1150dcdbd7e5140fbc5f9be7b"
}}

Todos

  • Tests
  • Documentation
  • Typings
  • Changelog

@pubkey
Copy link
Owner

pubkey commented Jun 10, 2022

Might be equal to #3812 (comment)
Can you check if this works with plain pouchdb? If not, this is a pouchdb bug and should reported at the pouchdb repo.

@nisarpeitang
Copy link
Author

I created a gist to verify the same routine on plain pouchdb and there's no error.

Output:

1-5191862503c07f65ec74a15df4a0aa86
{
  total_rows: 1,
  offset: 0,
  rows: [ { id: 'test', key: 'test', value: [Object] } ]
}
{ total_rows: 0, offset: 0, rows: [] }
3-7c210315d93a3c532db44e80e963e74f
{
  total_rows: 1,
  offset: 0,
  rows: [ { id: 'test', key: 'test', value: [Object] } ]
}
{ total_rows: 0, offset: 0, rows: [] }

The possible reason is that RxDB reset the rev when recreating the document with same id while pouchdb does not.

@pubkey
Copy link
Owner

pubkey commented Jun 14, 2022

I investigated a bit. Thank you for providing the tests, that really helped.

After the second insert, pouchDB works on the revision height 3 3-7c21031... while RxDB starts from 1 again 1-18fe9e5....
I think this behavior has changed in the latest PouchDB release.
The best solution in my opinion would be that RxDB also detects that the deleted document is re-inserted and then also inserts with revision height 3 instead of 1.

You can make a PR if you need this fixed. You should start by defining the correct behavior in the unit tests of the RxStorage interface.

@nisarpeitang
Copy link
Author

I will try to submit a PR to fix this issue.

pubkey added a commit that referenced this pull request Jul 9, 2022
pubkey added a commit that referenced this pull request Jul 10, 2022
* START working on a solution for #3839

* FIX pouchdb overwrite deleted

* FIX undelete for other RxStorage implementations

* FIX(dexie) re-insert deleted document

* ADD test from #3886

* ADD to changelog

* ADD docs
@pubkey
Copy link
Owner

pubkey commented Jul 10, 2022

Fixed here #3886

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

Successfully merging this pull request may close these issues.

2 participants