alkem-io / server

Core server in the Alkemio platform, offering a GraphQL api for interacting with the logical domain model.
http://alkem.io
European Union Public License 1.2
24 stars 4 forks source link

BUG: Returning of SpaceId on its creation fails from time to time #4141

Closed Comoque1 closed 1 week ago

Comoque1 commented 2 weeks ago

Describe the bug When running Space tests, they behaved unstable with latest server changes. There is one function containing 3:

  1. create space and get its id
  2. update space settings
  3. get space data

The issue happens, when trying to return the space id. Worked around the tests by putting a delay

image.png image.png

To Reproduce Steps to reproduce the behavior:

  1. Run command: npm run test:journey ./test/functional-api/journey/space/space.it-spec.ts

Additional information

The error is related to setting authorization policy again:

[NestWinston] Error     6/27/2024, 6:06:48 PM 
Duplicate entry '35a96b4d-a504-4109-a24b-f8332efb6656' for key 'authorization_policy.PRIMARY' - 
{
  "stack": [    {      "errorId": "5a4d2734-c727-4f40-a144-817eaeaa8155"    }  ],
  "error": {
    "query": "INSERT INTO `authorization_policy`(`id`, `createdDate`, `updatedDate`, `version`, `credentialRules`, `privilegeRules`, `verifiedCredentialRules`, `anonymousReadAccess`) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
    "parameters": [      "35a96b4d-a504-4109-a24b-f8332efb6656",      "2024-06-27T12:06:48.657Z",      "2024-06-27T12:06:48.657Z",      1,      "",      "",      "",      0    ],
    "driverError": {
      "code": "ER_DUP_ENTRY",
      "errno": 1062,
      "sqlState": "23000",
      "sqlMessage": "Duplicate entry '35a96b4d-a504-4109-a24b-f8332efb6656' for key 'authorization_policy.PRIMARY'",
      "sql": "INSERT INTO `authorization_policy`(`id`, `createdDate`, `updatedDate`, `version`, `credentialRules`, `privilegeRules`, `verifiedCredentialRules`, `anonymousReadAccess`) VALUES ('35a96b4d-a504-4109-a24b-f8332efb6656', '2024-06-27 15:06:48.657', '2024-06-27 15:06:48.657', 1, '', '', '', 0)"
    },
    "code": "ER_DUP_ENTRY",
    "errno": 1062,
    "sqlState": "23000",
    "sqlMessage": "Duplicate entry '35a96b4d-a504-4109-a24b-f8332efb6656' for key 'authorization_policy.PRIMARY'",
    "sql": "INSERT INTO `authorization_policy`(`id`, `createdDate`, `updatedDate`, `version`, `credentialRules`, `privilegeRules`, `verifiedCredentialRules`, `anonymousReadAccess`) VALUES ('35a96b4d-a504-4109-a24b-f8332efb6656', '2024-06-27 15:06:48.657', '2024-06-27 15:06:48.657', 1, '', '', '', 0)"
  },
  "query": "INSERT INTO `authorization_policy`(`id`, `createdDate`, `updatedDate`, `version`, `credentialRules`, `privilegeRules`, `verifiedCredentialRules`, `anonymousReadAccess`) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
  "parameters": [    "35a96b4d-a504-4109-a24b-f8332efb6656",    "2024-06-27T12:06:48.657Z",    "2024-06-27T12:06:48.657Z",    1,    "",    "",    "",    0  ],
  "driverError": {
    "code": "ER_DUP_ENTRY",
    "errno": 1062,
    "sqlState": "23000",
    "sqlMessage": "Duplicate entry '35a96b4d-a504-4109-a24b-f8332efb6656' for key 'authorization_policy.PRIMARY'",
    "sql": "INSERT INTO `authorization_policy`(`id`, `createdDate`, `updatedDate`, `version`, `credentialRules`, `privilegeRules`, `verifiedCredentialRules`, `anonymousReadAccess`) VALUES ('35a96b4d-a504-4109-a24b-f8332efb6656', '2024-06-27 15:06:48.657', '2024-06-27 15:06:48.657', 1, '', '', '', 0)"
  }
}

That is the actual error thrown by the server / MySQL.

Expected behavior Tests are robust, without a delay.

Comoque1 commented 1 week ago

After spending some times the issue happens on Account / Space creation. If you perform the mutation below, multiple times you are going to hit the error: Duplicate entry 'bd8e1315-c379-4746-b007-5b0207dfefd4' for key 'authorization_policy.PRIMARY'

mutation CreateAccount($accountData: CreateAccountInput!) {
  createAccount(accountData: $accountData) {
    id
    spaceID
  }
}
{
  "accountData": {
    "hostID": "b5361ba4-12bb-4f61-aa74-1a4ff35fdaf5",
    "spaceData": {
      "nameID": "112",
      "profileData": {
        "displayName": "112"
      }
    }
  }
}
image.png