amplify-js: DOMException: Failed to execute 'get' on 'IDBIndex': No key or key range specified when using Datastore.save on child element

Describe the bug When i use Datastore.save for a child element i get the following error:

DOMException: Failed to execute 'get' on 'IDBIndex': No key or key range specified

async add_vehicle({ commit, dispatch }, payload) {
    console.log('payload', payload)

    try {
      const resp = await DataStore.save(
        new Vehicle({
          enterpriseid: payload.enterprise.id,
          enterprise: new Enterprise(payload.enterprise),
          ownerid: payload.owner.sub,
          owner: new Enterprise(payload.owner),
          ...payload
        })
      )

      commit('add_vehicle_mutation', resp)
      dispatch('set_vehicleselected', resp)

      return resp
    } catch (err) {
      console.log('Error add_vehicle', err, payload)
      return err
    }
}

This error happen with different models, but I just explain with the vehicles since it’s the same behavior

To Reproduce Steps to reproduce the behavior:

  1. vue create xxx
  2. amplify init
  3. npm i @aws-amplify/core @aws-amplify/datastore
  4. amplify add api
  5. amplify codegen models

Code and Schema Link

Expected behavior I expect to save the objects locally and sync them with my Dynamo DB.

Screenshots image

What is Configured?

  • Which resources do you have configured?
    • API
    • Auth
    • Storage

OS: MacOs Catalina v10.15.7 Node: 14.15.1 Npm: 6.14.11 Chrome Browser v88.0.4324.96 Vue/Cli v4.5.10

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 22 (7 by maintainers)

Most upvoted comments

@iartemiev I removed them and it’s working fine. I guess there are a lot relationships or there is something there that causes that issue. I just remove the @connection directives but I left the field that made the relationship in each model. I update the Schema.

The way you’re using @connection is still incorrect in the schema. E.g., here. The @connection(name: "some name") syntax is deprecated and although it’s still supported by the API category, it won’t work correctly with DataStore.

For your 1:M relationships like Vehicle -> [ActivityHistory], you’ll want to use @connection with @key. For the 1:1 relationships you can omit the name and just do e.g.,

type Vehicle @model @auth(rules: [{ allow: public }]) {
  id: ID!
  owner: User @connection
  enterprise: Enterprise @connection