Closed sherl0cks closed 2 years ago
@jamesaucode this is a really scary bug for me. What can I do to help move forward triage? Do you need a full reproducer?
Hi @sherl0cks, are you still experiencing this behavior in the latest version of the library?
@iartemiev we are no longer using datastore because it does not support the dynamodb version control pattern. We are still using amplify, but we interact appsync through a simple axios client.
it does not seem deterministic which one is there.
I'm not exactly sure what you mean, the record that is synced and persisted to the client should always be the latest version from the server.
Both Post{ id: 1, version: 0} and Post{ id:1, version:1 } are stored in IndexedDB and available via DataStore.query.
Could you explain why you would expect two versions of the same record to be stored locally instead of the most recent version that was synced from the server? Curious about your use case and how or why DataStore doesn't seem to fulfill that requirement.
@chrisbonifacio we are using the dynamo db version control pattern which requires items to have a primary key with both partition key AND sort key. I’ve been told my aws support that datastore only supports uniquely identifying records by partition key. The version in question here is not the _version
from appsync conflict detection, but the version from the dynamo db version control pattern. Items have both fields, one for history, one for conflict detection. This allows users to view the history of the item in question, and thus why we need multiple records.
This works great without datastore. It would nice if datastore supported the use case.
@sherl0cks from your explanation of the requirements for your use case (partition and sort keys), it sounds like this might be supported by DataStore in the near future once support for custom primary keys is released. The PR for it has been merged, just waiting on public release.
In the meantime, a non-DataStore enabled GraphQL API would be the way to leverage the dynamodb version control pattern.
Closing this out as an answered question
Before opening, please confirm:
JavaScript Framework
Not applicable
Amplify APIs
DataStore
Amplify Categories
api
Environment information
Describe the bug
As context, I am building an application with DataStore and modeling data with the DynamoDB version control pattern.
I have application code in a backend process that is saving Post{ id: 1, version: 0} and Post{ id:1, version:1 }. This process also saves a DataStore record like `Event{ type: 'foo', postId: 1}, which I subscribe to via DataStore.observe. Upon receipt, I update DataStore selective sync according to the docs. In the network tab of the browser, I can see that both Post{ id: 1, version: 0} and Post{ id:1, version:1 } come over the wire on the sync query. However, when inspecting the DataStore indexeddb table for Post, I can see that it reliably only has 1 of the Post records, and that it does not seem deterministic which one is there.
Expected behavior
Both Post{ id: 1, version: 0} and Post{ id:1, version:1 } are stored in IndexedDB and available via DataStore.query.
Reproduction steps
Post
via the DataStore generatedcreatePost
GraphQL mutation. This should be done from a different process than the one queryingPosts
, whether that is cli / aws console / a different browser - it doesn't matter.Code Snippet
I have the model that follows a structure like:
I also have DataStore selective sync expressions that follow a structure like:
Log output
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response