Amplify-cli: A model with multiple keys will not allow removal or rearrangement of keys

Created on 30 Nov 2020  路  9Comments  路  Source: aws-amplify/amplify-cli

Describe the bug
A model with multiple keys will not allow removal of keys from the top of the list. I also cannot re-arrange the order of the keys in the list. I CAN remove keys from the bottom of the list.

I can also add new keys just fine to the top or bottom or the list.

Amplify CLI Version
4.36.2

To Reproduce
create and publish an api model using graphql:

type MyType
@model
@key(name: "MyKey", fields: ["type","name"])
@key(name: "AnotherKey", fields: ["type","anotherString"])
# etc...
{
id: ID!
name: String
type: String
anotherString: String
}

Now remove one key and try to republish:

type MyType
@model
@key(name: "MyKey", fields: ["type","name"])
#@key(name: "AnotherKey", fields: ["type","anotherString"])
# etc...
{
id: ID!
name: String
type: String
anotherString: String
}

or rearrange them:

type MyType
@model
@key(name: "AnotherKey", fields: ["type","anotherString"])
@key(name: "MyKey", fields: ["type","name"])
# etc...
{
id: ID!
name: String
type: String
anotherString: String
}

You get:
An error occurred when pushing the resources to the cloud

Attempting to mutate more than 1 global secondary index at the same time on the MyTypeTable table in the Item stack.
An error occurred during the push operation: Attempting to mutate more than 1 global secondary index at the same time on the MyTypeTable table in the MyType stack.

Expected behavior
I expect it to remove the GSI in the cloud through a normal push. In the second case, rearrange, I expect it to recognize no substantive change was made.

Screenshots
N/A

Desktop (please complete the following information):
Windows 10 64 bit
Node 12.18.4

Additional context
N/A

bug graphql-transformer

All 9 comments

@ryanhollander What version of the CLI are you using? I was not able to reproduce with version 4.37.0.

@SwaySway
Amplify CLI Version
4.36.2

Thanks. I'll try again with the latest CLI.

I've found I can also get this error by deleting an existing key that isn't the last one!

Given this Model (this isn't the full schema just the model in question, I have emailed that over though as mentioned in #6050):

type Address
  @model
  @searchable
  @auth(
    rules: [
      { allow: groups, groups: ["admin"] }
      { allow: public, provider: apiKey }
    ]
  )
  @key(name: "byArea", fields: ["areaID"], queryField: "addressesByArea")
  @key(
    name: "byStatus"
    fields: ["addressStatusID"]
    queryField: "addressesByStatus"
  )
  @key(
    name: "byCustomer"
    fields: ["customerID"]
    queryField: "addressesByCustomerIDAndStatus"
  )
  @key(
    name: "byAreaAndStatus"
    fields: ["areaID", "addressStatusID"]
    queryField: "addressesByAreaAndStatus"
  ) {
  id: ID!
  companyName: String
  addressLine1: String!
  addressLine2: String
  addressLine3: String
  town: String
  county: String
  postcode: String!
  phoneNumber: String
  bedrooms: Int!
  houseTypeID: ID!
  houseType: HouseType @connection(fields: ["houseTypeID"])
  hasConservatory: Boolean
  customerID: ID!
  customer: Customer! @connection(fields: ["customerID"])
  addressStatusID: ID!
  addressStatus: AddressStatus!
  comments: [Comment] @connection(fields: ["id"])
  subscribedServices: [ServiceSubscription] @connection(fields: ["id"])
  areaID: ID!
  area: Area @connection(fields: ["areaID"])
  # Following comes from the Postcode look up service
  geoCords: Location
  buildNumber: String
  buildName: String
  premise: String # A helper of the above two fields merged into a displayName
  """
  The first half of the postcode (eg HD7, SW11)
  """
  postcodeOutward: String
  """
  The second half of the postcode (eg 5NF)
  """
  postcodeInward: String
  signUpDate: AWSDateTime
}

If I try to change or remove any of the keys except the last one it will throw the error mentioned at the top of the issue.

Having to remove them one by one in reserve order and do a push inbetween each...not the fastest way to develop :(

I'm using v4.37.1

@SwaySway still not working with 4.37.1

@PeteDuncanson I am experiencing the same. FWIW: This is a fresh API I created recently with the most recent version of the cli as of about 3 weeks ago.

Just taken me 90+ minutes to modify my keys. Had to remove all 4 then re-add the 2 I wanted with changes. 90...minutes....

And due to #6028 I can't work on other code either :(

This feels like the old FTP days on dial up

@PeteDuncanson Yikes! I'm hoping someone fixes this before I have to do that as well.

Hey @SwaySway can you give this another go/look?

@PeteDuncanson I was able to reproduce this. It looks like adding the hash key as a range key is what caused it to view this as a new GSI addition, which then triggers the error.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

amlcodes picture amlcodes  路  3Comments

kstro21 picture kstro21  路  3Comments

davo301 picture davo301  路  3Comments

zjullion picture zjullion  路  3Comments

onlybakam picture onlybakam  路  3Comments