Delete or Create key fails: Attempting to mutate more than 1 global secondary index at the same time
Describe the bug
When attempting to delete a single key (no other changes) I get:
Attempting to mutate more than 1 global secondary index at the same time on the FooTable table in the Foo stack.
An error occurred during the push operation: Attempting to mutate more than 1 global secondary index at the same time on the FooTable table in the Foo stack.
Amplify CLI Version
4.29.2
To Reproduce
- Have a schema that has already been pushed with an example
@key - Try to delete the
@key amplify pushfails
Expected behavior
@key should be deleted
Additional context
Example schema:
type Foo
@model
@key(name: "FooStatusUpdatedAt", fields: ["status", "updatedAt"], queryField: "fooStatusUpdatedAt")
@searchable
{
updatedAt: AWSDateTime,
status: PublicationStatus,
...
}
enum PublicationStatus {
draft
}
Note: I downgraded to @aws-amplify/[email protected] and was able to perform the amplify push without issue.
@malcomm was the initial push with an older version?
@ammarkarachi - no I just added this key today and pushed and attempted to delete it all with 4.29.2. The model was initially created with an older version and has had various updates.
I ended up using this query to add and delete the GSI with some data, I was able to push to successfully in both instances. It could be the GSI was getting updated when the delete that being counted as another mutation.
type Foo
@model
@key(name: "FooStatusUpdatedAt", fields: ["status", "updatedAt"], queryField: "fooStatusUpdatedAt")
{
updatedAt: AWSDateTime,
status: PublicationStatus,
}
enum PublicationStatus {
draft
}
@ammarkarachi - I just commented out the the line and did a push. I am no longer blocked by this so not sure what happened exactly.
@malcomm Alright let me know if there is anything else, Thanks
@ammarkarachi
OK I just ran into a very similar issue. Here's the original schema:
type Foo
@model
@key(name: "FooSubjectId", fields: ["fooSubjectId"], queryField: "fooSubjectId")
{
id: ID!,
updatedAt: AWSDateTime,
fooSubjectId: ID!,
searchIndex: String,
...
}
Adding a single key like this:
type Foo
@model
@key(name: "FooByUpdatedAt", fields: ["searchIndex", "updatedAt"], queryField: "fooByUpdatedAt")
@key(name: "FooSubjectId", fields: ["fooSubjectId"], queryField: "fooSubjectId")
{
id: ID!,
updatedAt: AWSDateTime,
fooSubjectId: ID!,
searchIndex: String,
...
}
Is resulting in:
Attempting to mutate more than 1 global secondary index at the same time on the FooTable table in the Foo stack.
An error occurred during the push operation: Attempting to mutate more than 1 global secondary index at the same time on the FooTable table in the Foo stack.
Note:
- I'm using
4.29.3of@amplify/cli - The table has been around for a long time (more than a year)
I have the same problem, and I just found out that the order of the @key directives seems to matter.
Going from this:
type Foo
@model
@key(name: "FooSubjectId", fields: ["fooSubjectId"], queryField: "fooSubjectId")
to this:
type Foo
@model
@key(name: "FooByUpdatedAt", fields: ["searchIndex", "updatedAt"], queryField: "fooByUpdatedAt")
@key(name: "FooSubjectId", fields: ["fooSubjectId"], queryField: "fooSubjectId")
results in abovementioned error, but instead doing:
type Foo
@model
@key(name: "FooSubjectId", fields: ["fooSubjectId"], queryField: "fooSubjectId")
@key(name: "FooByUpdatedAt", fields: ["searchIndex", "updatedAt"], queryField: "fooByUpdatedAt")
seems to work. My guess is that the diffing in the first case creates something like this:
DELETE FooSubjectId
CREATE FooByUpdatedAt
CREATE FooSubjectId
instead of this:
CREATE FooByUpdatedAt
@dsypniewski - thank you for the potential workaround. I was hopeful that it would work, but I tried messing around the order and I still got the error.
@malcomm Have you tried to compare your schema.graphql with the one in #current-cloud-backend ? Those two files should be exactly the same except one line with the new @key after all the existing ones for that model.
@dsypniewski - I just compared them and the only diff is the @key.
@ammarkarachi - any updates on this? This is blocking a production fix.
@malcomm same issue for me and reverse the order of the @key didn't work for me. Amplify will push it as long as I have a single @key.
Just figured out my issue was caused by the following field:
@key(name: "MessagesByAuthor", fields: ["authorId", "createdAt"], queryField: "messagesByAuthor")
...
author: User @connection(name: "MessagesByAuthor")
...
This caused amplify to build another index gsi-MessagesByAuthor on top of the @key directive I was trying to use. This indeed was forcing amplify to create two gsi. What I should have done was just define the field instead name for the author connection.
Getting the same problem. I am running amplify cli 4.29.8
I am trying to add-in
@key(
name: "ActionLogsByCaseId"
fields: ["actionLogCaseId"]
queryField: "actionLogsByCaseId"
)
to this existing model... never had problems doing this before. I have also tried putting it in different positions within the schema but no luck.
type ActionLog implements Meta
@model
@auth(
rules: [
{ allow: owner }
{
allow: groups
groupsField: "actionLogAccountId"
operations: [create, update, read]
}
{ allow: groups, groups: ["Admin"] }
]
)
@key(
name: "ActionLogsByCompletedAt"
fields: ["completedAt"]
queryField: "actionLogsByCompletedAt"
)
@key(
name: "ActionLogsByOwner"
fields: ["owner", "createdAt"]
queryField: "actionLogsByOwner"
)
@key(
name: "ActionLogsByActionId"
fields: ["actionLogActionId", "createdAt"]
queryField: "actionLogsByActionId"
)
@key(
name: "ActionLogsByAccountId"
fields: ["actionLogAccountId", "createdAt"]
queryField: "actionLogsByAccountId"
) {
id: ID!
completedAt: AWSDateTime
case: Case! @connection(name: "ActionCaseLogs")
actionLogCaseId: ID!
owner: String
user: LimitedUser @function(name: "getUser-${env}")
action: Action! @connection(name: "ActionLogs")
actionLogActionId: ID!
account: Account! @connection(name: "AccountActionLogs")
actionLogAccountId: ID!
type: ActionLogType
# Meta Data
createdAt: AWSDateTime
updatedAt: AWSDateTime
deletedAt: AWSDateTime
}
Also have this issue and I'm just trying to delete a single key.
@key(
name: "CandidateByShortLink"
fields: ["shortLink"]
)
@key(
name: "CandidateByOfficialLocation"
fields: ["officialLocationId", "positionTitle"],
queryField: "candidatesByOfficialLocation"
)
@key(
name: "CandidateByVerificationStatus"
fields: ["verification", "verificationDateTime"]
queryField: "candidatesByVerificationStatus"
)
to
@key(
name: "CandidateByOfficialLocation"
fields: ["officialLocationId", "positionTitle"],
queryField: "candidatesByOfficialLocation"
)
@key(
name: "CandidateByVerificationStatus"
fields: ["verification", "verificationDateTime"]
queryField: "candidatesByVerificationStatus"
)
@andrewbtp do you have any table field connection to the "CandidateByShortLink" key?
For example:
fieldname: String @connection(name: "CandidateByShortLink")
@tsesamson Nope. I was able to remove the key by reverting to @aws-amplify/[email protected]
I had the same issue. After downgrading it worked @andrewbtp .
Hello, I have the same issue using the @aws-amplify/[email protected].
I don't have much to offer in terms of clarifying this issue, I just wanted to let you know that it happens to other people as well.
I have an unused @key in the schema named byDomainUrl:
# TODO remove byDomainUrl key
type Product
@model
@key(name: "byDomain", fields: ["domainID"], queryField: "productsByDomain")
@key(name: "byDomainUrl", fields: ["domainID", "url"], queryField: "productsByDomainUrl")
@key(name: "byUrl", fields: ["url"], queryField: "productByUrl")
@key(name: "byDomainOriginalId", fields: ["domainID", "originalId"], queryField: "productByDomainOriginalId")
@key(name: "byDomainPopularity", fields: ["domainID", "popularity"], queryField: "productsByDomainPopularity")
@auth(rules: [{ allow: private, provider: iam }, { allow: private, operations:[read], provider: userPools }])
{
id: ID!
domainID: ID!
domain: Domain @connection(fields: ["domainID"])
url: String!
name: String!
description: String
price: Float
image: String
originalImage: String!
originalId: String!
category: [String!]!
popularity: Int
}
I can't remove the byDomainUrl key, getting the same error message: Attempting to mutate more than 1 global secondary index at the same time on the ProductTable table in the Product stack. An error occurred during the push operation: Attempting to mutate more than 1 global secondary index at the same time on the ProductTable table in the Product stack.
The schema (and the DynamoDB GSI index) was created with one of the previous Amplify CLI versions, but I don't know which. I update regularly, and I started working on this project at the beginning of August.
I don't use the @key in any @connection.
I'm having the same issue using a custom CloudFormation resource containing a DynamoDB table. I'm only removing a previously created index from the file and Amplify doesn't want to push.
I'm downgrading to @aws-amplify/[email protected] as a workaround, but that's not ideal - especially when deploying in production from the console.