twentyhq / twenty

Building a modern alternative to Salesforce, powered by the community.
https://twenty.com
Other
23.63k stars 2.43k forks source link

Error 'missing FROM-clause entry for table "workspacemember"' doesn't allow deleting or creating new members #7449

Open BOHEUS opened 1 month ago

BOHEUS commented 1 month ago

Scenario:

  1. Log in
  2. Go to Settings > Members
  3. Delete any member created by system

Actual: Member is not deleted and error is thrown Screencast From 2024-10-05 10-54-33.webm

Expected: Member must be deleted

query failed: UPDATE "workspace_1wgvd1injqtife6y4rvfbu3h5"."workspaceMember" SET "deletedAt" = $1, "updatedAt" = CURRENT_TIMESTAMP WHERE workspaceMember.id = $2 RETURNING * -- PARAMETERS: ["2024-10-05T08:54:36.044Z","20202020-77d5-4cb6-b60a-f4a835a85d61"]
error: error: missing FROM-clause entry for table "workspacemember"
Exception Captured
  {
    operation: { name: 'DeleteOneWorkspaceMember', type: 'mutation' },
    document: 'mutation DeleteOneWorkspaceMember($idToDelete: ID!) {\n' +
      '  deleteWorkspaceMember(id: $idToDelete) {\n' +
      '    __typename\n' +
      '    id\n' +
      '    deletedAt\n' +
      '  }\n' +
      '}',
    user: User {
      id: '20202020-9e3b-46d4-a556-88b9ddc2b034',
      firstName: 'Tim',
      lastName: 'Apple',
      email: 'tim@apple.dev',
      defaultAvatarUrl: null,
      emailVerified: false,
      disabled: false,
      passwordHash: '$2b$10$66d.6DuQExxnrfI9rMqOg.U1XIYpagr6Lv05uoWLYbYmtK0HDIvS6',
      canImpersonate: false,
      createdAt: 2024-10-03T23:11:02.911Z,
      updatedAt: 2024-10-04T18:26:59.846Z,
      deletedAt: null,
      defaultWorkspaceId: '20202020-1c25-4d02-bf25-6aeccf7ea419'
    }
  }
  [
    QueryFailedError: missing FROM-clause entry for table "workspacemember"
        at PostgresQueryRunner.query (/home/mk/Desktop/projects/twenty/src/driver/postgres/PostgresQueryRunner.ts:331:19)
        at processTicksAndRejections (node:internal/process/task_queues:95:5)
        at UpdateQueryBuilder.execute (/home/mk/Desktop/projects/twenty/src/query-builder/UpdateQueryBuilder.ts:145:33)
        at GraphqlQueryUpdateOneResolverService.resolve (/home/mk/Desktop/projects/twenty/packages/twenty-server/src/engine/api/graphql/graphql-query-runner/resolvers/graphql-query-update-one-resolver.service.ts:68:20)
        at GraphqlQueryRunnerService.executeQuery (/home/mk/Desktop/projects/twenty/packages/twenty-server/src/engine/api/graphql/graphql-query-runner/graphql-query-runner.service.ts:334:21)
        at GraphqlQueryRunnerService.deleteOne (/home/mk/Desktop/projects/twenty/packages/twenty-server/src/engine/api/graphql/graphql-query-runner/graphql-query-runner.service.ts:221:20)
        at GraphqlQueryRunnerService.descriptor.value (/home/mk/Desktop/projects/twenty/packages/twenty-server/src/engine/decorators/observability/log-execution-time.decorator.ts:20:22)
        at Object.deleteWorkspaceMember (/home/mk/Desktop/projects/twenty/packages/twenty-server/src/engine/api/graphql/workspace-resolver-builder/factories/delete-one-resolver.factory.ts:53:18)
        at field.resolve (/home/mk/Desktop/projects/twenty/node_modules/@envelop/on-resolve/cjs/index.js:36:42)
        at /home/mk/Desktop/projects/twenty/node_modules/@envelop/core/cjs/orchestrator.js:383:27 {
      path: undefined,
      locations: undefined,
      extensions: {
        code: 'INTERNAL_SERVER_ERROR',
        response: 'missing FROM-clause entry for table "workspacemember"'
      }
    }
  ]
BOHEUS commented 1 month ago

Scenario:

  1. Log in
  2. Go to Settings > Members
  3. Copy invite link
  4. Logout
  5. Paste copied link and create new account

Actual: System won't allow finishing creating new account Screencast From 2024-10-05 11-01-22.webm

Expected: User can create new account

BOHEUS commented 1 month ago

This problem also appears when user tries to change anything in Settings > Experience, Settings > Accounts > Emails, Settings > Accounts > Calendar, creates new API key or webhook in Settings > API & Webhooks, hides any field in object's tab > Options > Fields

charlesBochet commented 1 month ago

@BOHEUS is that on main our on prod (0.30.2) ?

BOHEUS commented 1 month ago

@charlesBochet I've found it locally after pulling newest changes, checked demo as I don't have paid version and is seems like this bug isn't there (there's different bug with inviting new people, but that's topic for another issue)

BOHEUS commented 1 month ago

Database logs

twenty_postgres  | 2024-10-05 11:38:20.005 GMT [1012] ERROR:  missing FROM-clause entry for table "workspacemember" at character 126
twenty_postgres  | 2024-10-05 11:38:20.005 GMT [1012] STATEMENT:  UPDATE "workspace_1wgvd1injqtife6y4rvfbu3h5"."workspaceMember" SET "colorScheme" = $1, "updatedAt" = CURRENT_TIMESTAMP WHERE workspaceMember.id = $2 RETURNING *
charlesBochet commented 1 month ago

Ok @Weiko will likely take a close look on Monday, thanks for spotting it!

Weiko commented 1 month ago

This one should have been fixed already, I can't reproduce on main. Can you try again? @BOHEUS

BOHEUS commented 1 month ago

Sure, I'll fetch newest changes and check it ASAP

BOHEUS commented 1 month ago

I'm closing this as I can't also reproduce it after pulling newest changes from main

BOHEUS commented 3 days ago

I'm reopening this as I'm able to reproduce it on main and also, ticket was created by one of users https://discord.com/channels/1130383047699738754/1310321595457470504

CC: @Weiko

BOHEUS commented 3 days ago

Btw, it's also reproducible on demo, what a sneaky one https://github.com/user-attachments/assets/a18b1c53-871d-4c1b-b9aa-a72a2db34974