Amplify-cli: Models not saving due to incorrect data model, again.

Created on 4 Mar 2020  路  10Comments  路  Source: aws-amplify/amplify-cli

Describe the bug
This morning all my saves had stopped working. Again.

To Reproduce

  1. Add any model, with an undefined "createdAt".
  2. DataStore sync comes back with an error. This error also seems to be impossible to solve.

Expected behavior
Sync should work. Or the error should allow me to debug.
It is also surprising that my app changes behavior even though _I'm not making any changes_. How is that happening? No packages were updated?

Screenshots
Original error:
Screenshot 2020-03-04 at 17 00 40

Empty string added:
Screenshot 2020-03-04 at 17 00 09

Date string added:
Screenshot 2020-03-04 at 17 00 16

Date ISO string added:
Screenshot 2020-03-04 at 17 03 39

Seems like AppSync has changed how it handles models, but updating my packages does nothing?

DataStore bug dependency-issue

Most helpful comment

@mauerbac Can we get an update on this please?

All 10 comments

Running the mutation from the AppSync console works fine, with the same data. So this seems to be a syncing error in datastore. If I discover anything else I'll update this thread.

This is the schema:

type Ting
  @model
  @auth(rules: [{ allow: owner }, { allow: groups, groups: ["admins"] }]) {
  id: ID!
  createdAt: AWSDateTime
  references: [String]
  referencedBy: [String]
  content: String!
  access: [UserTing] @connection(keyName: "byUser", fields: ["id"])
}

If I run DataStore locally from the amplify-js repo, it works fine. So this is only an issue in NPM version 1.0.8 of DataStore

After additional testing it turns out that adding a ISO date string allows the model to save and sync properly, I'm only being warned that something's wrong. This warning is silenced when running DataStore from the local repo instead.

Some update must have caused us to start having to send createdAt?

Still having this issue, if an array is empty it doesn't save.
If an array only contains an empty string, it doesn't save.

@sammartinez I really need nullable lists in my schema for the app I am working on. Can this be added to the DataStore milestone?

@Ashish-Nanda Any progress on this? My company has an app that we are looking to ship on June 1st.

@mauerbac Can we get an update on this please?

I believe closed issue #5292 described the situation I am facing more clearly than aws-amplify/amplify-js#5040

It seems to be impossible to retrieve an object with an empty or null array from DynamoDB through Datastore.

For a given property :

  • When I use [String!]!, I would expect to be able to retreive an empty array.

  • When I use [String!], I would expect to be able to retrieve a null/undefined value for the array.
    Instead, I get _Error: Field presets should be of type string[], objects received. null_

A workaround is to store the object with an array containing an empty string : [""].

Empty arrays are common in any kind of app. Shouldn't this be prioritized accordingly?

I believe closed issue #5292 described the situation I am facing more clearly than aws-amplify/amplify-js#5040

It seems to be impossible to retrieve an object with an empty or null array from DynamoDB through Datastore.

For a given property :

  • When I use [String!]!, I would expect to be able to retreive an empty array.
  • When I use [String!], I would expect to be able to retrieve a null/undefined value for the array.
    Instead, I get _Error: Field presets should be of type string[], objects received. null_

A workaround is to store the object with an array containing an empty string : [""].

Empty arrays are common in any kind of app. Shouldn't this be prioritized accordingly?

@valtrem
As far as I understand the GraphQL notation with the exclamation points, it should be implemented as follows (https://stackoverflow.com/questions/46770501/graphql-non-nullable-array-list):

| declaration | null | [] | [null] | [{ foo: 'BAR' }] |
|-------------|------|-----|--------|------------------|
| [Type!]! | no | yes | no | yes |
| [Type]! | no | yes | yes | yes |
| [Type!] | yes | yes | no | yes |
| [Type] | yes | yes | yes | yes |

However using [Type] does not allow null values or empty array, but requires the hacky workaround you described.

Is it possible, that [Type] and [Type!] are not implemented because DynamoDB does not let you update a List or a Map attribute if it does not exist beforehand? This would at least be an acceptable explanation, should however be covered by the docs.

Upon further investigation, I would consider the validateModelFields to be the cause of the problem. Esp. line 244 seems problematic

!Array.isArray(v)

should in my eyes be

!Array.isArray(v) && isRequired

to address the GraphQL declarations.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

YikSanChan picture YikSanChan  路  3Comments

davo301 picture davo301  路  3Comments

onlybakam picture onlybakam  路  3Comments

ReidWeb picture ReidWeb  路  3Comments

gabriel-wilkes picture gabriel-wilkes  路  3Comments