-
Notifications
You must be signed in to change notification settings - Fork 198
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
[DataStore] Model cannot be synced to cloud due to index field is null #1390
Comments
the generated model and schema (amplify CLI 5.0.1) // swiftlint:disable all
import Amplify
import Foundation
public struct TestModel: Model {
public let id: String
public var content: String
public var parentId: String?
public var createdAt: Temporal.DateTime?
public var updatedAt: Temporal.DateTime?
public init(id: String = UUID().uuidString,
content: String,
parentId: String? = nil) {
self.init(id: id,
content: content,
parentId: parentId,
createdAt: nil,
updatedAt: nil)
}
internal init(id: String = UUID().uuidString,
content: String,
parentId: String? = nil,
createdAt: Temporal.DateTime? = nil,
updatedAt: Temporal.DateTime? = nil) {
self.id = id
self.content = content
self.parentId = parentId
self.createdAt = createdAt
self.updatedAt = updatedAt
}
}
// swiftlint:disable all
import Amplify
import Foundation
extension TestModel {
// MARK: - CodingKeys
public enum CodingKeys: String, ModelKey {
case id
case content
case parentId
case createdAt
case updatedAt
}
public static let keys = CodingKeys.self
// MARK: - ModelSchema
public static let schema = defineSchema { model in
let testModel = TestModel.keys
model.pluralName = "TestModels"
model.fields(
.id(),
.field(testModel.content, is: .required, ofType: .string),
.field(testModel.parentId, is: .optional, ofType: .string),
.field(testModel.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime),
.field(testModel.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime)
)
}
} |
Is the expectation that when no parentId is passed in, then parentId should be empty string
can you clarify this as well? do you mean the errorHandler registered and is not called? as I recall, if this is being built for flutter, the errorHandler is not exposed (yet)
So what happens if you try to retrieve it again from AppSync? |
currently iOS DataStore will sync all the fields from the model instance, so when there is no personId field, ideally, we do per field syncing such that when a create mutation is created, since we should also consider data manipulation afterwards: If the model is then synced to the local store, and then retrieved using DataStore.query, and updated using DataStore.save(), then what will the update mutation have when syncing to the cloud? |
For this case,
Yes Flutter is missing
As the model now cannot be synced to cloud, there was no retrieving happened. But you possibly can test the query MyQuery {
listTestModels {
items {
parentId
id
content
}
}
} Returns below result {
"data": {
"listTestModels": {
"items": [
{
"parentId": "1234",
"id": "b2595335-b118-440b-aac3-0fc8a07592e5",
"content": "Test model with parentID null"
},
{
"parentId": null,
"id": "1bbdba5f-7dcd-450e-ac8d-de54885dd47f",
"content": "Test content"
},
{
"parentId": null,
"id": "b2595225-b118-440b-aac3-0fc8a07592e5",
"content": "Test model with parentID null"
}
]
}
}
} For the empty |
thanks for the quick response, I think field-level saves and updates may end up fixing this. Alternatively we could be more explicit either in the library or Appsync service. If secondary index at the DynamoDB level can be empty but not null, then can AppSync API accept |
type SecondIndexModel @model {
id: ID! @primaryKey
parentID: ID @index(name: "parent-id-index")
} When If there is no requirement to fix for v1, please close accordingly, thanks! Update: this issue is still reproducible with transform v2 |
Amplify CLI opened an issue for looking for a solution aws-amplify/amplify-cli#9915 |
The underlying issue has been fixed on Amplify CLI side. Please ensure upgrade to Amplify CLI version >=8.0.2, and re-deploy schema (regenerate resolvers). |
Describe the bug
When saving a model with below schema, if the index field is not assigned, model can only be saved into local DB, but failed syncing to DynamoDB. In addition, amplify-ios doesn't report the underlying GraphQL error on invoking
DataStore.save
API.Original debugging please refer to aws-amplify/amplify-flutter#306 (comment)
Same issue in amplify-android: aws-amplify/amplify-android#1461
Steps To Reproduce
Expected behavior
Amplify Framework Version
1.13.3
Amplify Categories
DataStore
Dependency manager
Swift PM
Swift version
5
CLI version
5.3.0
Xcode version
12.5.1
Relevant log output
No response
Is this a regression? (i.e. was this working before a version upgrade)
No response
Device
iPhone 12 simulators
iOS Version
iOS 14.5
Specific to simulators
No response
Additional context
Swift code used for testing
Above code executed successfully, there is error message observed in debug console.
GraphQL request
GraphQL response
After removing
parentId: null
fromvariables
, model can be synced into DynamoDB.The text was updated successfully, but these errors were encountered: