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

findRecord intermittently fails with inconsistent document structure #266

Open
backspace opened this issue Dec 22, 2023 · 0 comments
Open

Comments

@backspace
Copy link
Collaborator

I’m working on adding conflict detection during sync and I’m encountering a strange inconsistent bug. Sometimes the sync and subsequent scan for conflicts succeeds, sometimes I get errors like this:

TypeError: Cannot set properties of undefined (setting 'id')
    at fromRawDoc (webpack://__ember_auto_import__/./node_modules/.pnpm/[email protected][email protected]/node_modules/relational-pouch/lib/index.js?:24:66)
    at _parseRelDocs (webpack://__ember_auto_import__/./node_modules/.pnpm/[email protected][email protected]/node_modules/relational-pouch/lib/index.js?:29:720)
    at _parseAlldocs (webpack://__ember_auto_import__/./node_modules/.pnpm/[email protected][email protected]/node_modules/relational-pouch/lib/index.js?:29:281)
    at _find (webpack://__ember_auto_import__/./node_modules/.pnpm/[email protected][email protected]/node_modules/relational-pouch/lib/index.js?:28:94)
    at async Class._findRecord (http://localhost:4190/assets/vendor.js:91649:21)

Looking at the function in question, frowRawDoc, the problem is that pouchDoc.data is sometimes undefined, like this:

{
  "name": "A region version 100",
  "_id": "region_2_778B4E9D-8C63-7D27-B28E-CBA85B8F8F97",
  "_rev": "2-a526bf91fa35aaceedf48f58dca458ad"
}

When the error doesn’t happen (most of the time) pouchDoc is the expected structure:

{
  "data": {
    "name": "A region",
    "hours": null,
    "accessibility": null,
    "notes": null,
    "x": null,
    "y": null,
    "createdAt": "2023-12-21T23:54:45.357Z",
    "updatedAt": "2023-12-21T23:54:45.357Z",
    "parent": null,
    "children": [],
    "destinations": [],
    "waypoints": []
  },
  "_id": "region_2_03F56E18-9ABB-B9AC-A0FB-8794D982CD1A",
  "_rev": "1-57da2cebd4d756df32f6b4205dbd577d"
}

The code for finding conflicts is here, it uses allDocs (with include_docs) but you can see in the commented-out code that I tried watching changes too, which actually seemed to produce more errors. Is this how people are working with conflicts, is there any way we can make them first-class with Ember Pouch models?

The actual failures are happening in relational-pouch but I’m not sure which library is actually at fault.

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

No branches or pull requests

1 participant