Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deleteAccount runtime exception due to "event_createdByUserId_foreign" foreign key constraint #70

Closed
gianlazz opened this issue May 26, 2024 · 0 comments · Fixed by #71
Labels
bug Something isn't working

Comments

@gianlazz
Copy link
Member

[Nest] 35921  - 05/26/2024, 3:59:31 PM   DEBUG [JwtStrategy] verified access token.
[query] begin
[query] select "u0".* from "user" as "u0" where "u0"."id" = 1 limit 1 [took 2 ms, 1 result]
[Nest] 35921  - 05/26/2024, 3:59:32 PM   DEBUG [JwtStrategy] verified user
[query] update "user" set "last_online" = '1716764372002' where "id" = 1 [took 17 ms]
[query] commit
[Nest] 35921  - 05/26/2024, 3:59:32 PM   DEBUG [AuthResolver] deleteAccount
[Nest] 35921  - 05/26/2024, 3:59:32 PM   DEBUG [AuthService] deleteAccount
[query] begin
[query] delete from "user" where "id" in (1) [took 2 ms]
[query] rollback
[Nest] 35921  - 05/26/2024, 3:59:32 PM   ERROR [ExceptionsHandler] delete from "user" where "id" in (1) - update or delete on table "user" violates foreign key constraint "event_createdByUserId_foreign" on table "event"
ForeignKeyConstraintViolationException: delete from "user" where "id" in (1) - update or delete on table "user" violates foreign key constraint "event_createdByUserId_foreign" on table "event"
    at PostgreSqlExceptionConverter.convertException (/Users/gianlazzarini/Documents/Development/Lazztech.Hub-Service/node_modules/@mikro-orm/postgresql/PostgreSqlExceptionConverter.js:26:24)
    at PostgreSqlDriver.convertException (/Users/gianlazzarini/Documents/Development/Lazztech.Hub-Service/node_modules/@mikro-orm/core/drivers/DatabaseDriver.js:201:54)
    at /Users/gianlazzarini/Documents/Development/Lazztech.Hub-Service/node_modules/@mikro-orm/core/drivers/DatabaseDriver.js:205:24
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at ChangeSetPersister.executeDeletes (/Users/gianlazzarini/Documents/Development/Lazztech.Hub-Service/node_modules/@mikro-orm/core/unit-of-work/ChangeSetPersister.js:57:13)
    at ChangeSetPersister.runForEachSchema (/Users/gianlazzarini/Documents/Development/Lazztech.Hub-Service/node_modules/@mikro-orm/core/unit-of-work/ChangeSetPersister.js:69:13)
    at UnitOfWork.commitDeleteChangeSets (/Users/gianlazzarini/Documents/Development/Lazztech.Hub-Service/node_modules/@mikro-orm/core/unit-of-work/UnitOfWork.js:806:9)
    at UnitOfWork.persistToDatabase (/Users/gianlazzarini/Documents/Development/Lazztech.Hub-Service/node_modules/@mikro-orm/core/unit-of-work/UnitOfWork.js:720:13)
    at PostgreSqlConnection.transactional (/Users/gianlazzarini/Documents/Development/Lazztech.Hub-Service/node_modules/@mikro-orm/knex/AbstractSqlConnection.js:36:25)
    at UnitOfWork.doCommit (/Users/gianlazzarini/Documents/Development/Lazztech.Hub-Service/node_modules/@mikro-orm/core/unit-of-work/UnitOfWork.js:295:17)
    at UnitOfWork.commit (/Users/gianlazzarini/Documents/Development/Lazztech.Hub-Service/node_modules/@mikro-orm/core/unit-of-work/UnitOfWork.js:268:13)
    at SqlEntityManager.flush (/Users/gianlazzarini/Documents/Development/Lazztech.Hub-Service/node_modules/@mikro-orm/core/EntityManager.js:1128:9)
    at SqlEntityManager.removeAndFlush (/Users/gianlazzarini/Documents/Development/Lazztech.Hub-Service/node_modules/@mikro-orm/core/EntityManager.js:1112:9)
    at SqlEntityRepository.removeAndFlush (/Users/gianlazzarini/Documents/Development/Lazztech.Hub-Service/node_modules/@mikro-orm/core/entity/EntityRepository.js:142:9)
    at AuthService.deleteAccount (/Users/gianlazzarini/Documents/Development/Lazztech.Hub-Service/src/auth/auth.service.ts:148:7)
    at AuthResolver.deleteAccount (/Users/gianlazzarini/Documents/Development/Lazztech.Hub-Service/src/auth/auth.resolver.ts:112:20)

previous error: delete from "user" where "id" in (1) - update or delete on table "user" violates foreign key constraint "event_createdByUserId_foreign" on table "event"
    at Parser.parseErrorMessage (/Users/gianlazzarini/Documents/Development/Lazztech.Hub-Service/node_modules/pg-protocol/src/parser.ts:369:69)
    at Parser.handlePacket (/Users/gianlazzarini/Documents/Development/Lazztech.Hub-Service/node_modules/pg-protocol/src/parser.ts:188:21)
    at Parser.parse (/Users/gianlazzarini/Documents/Development/Lazztech.Hub-Service/node_modules/pg-protocol/src/parser.ts:103:30)
    at Socket.<anonymous> (/Users/gianlazzarini/Documents/Development/Lazztech.Hub-Service/node_modules/pg-protocol/src/index.ts:7:48)
    at Socket.emit (node:events:519:28)
    at Socket.emit (node:domain:488:12)
    at addChunk (node:internal/streams/readable:559:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
    at Socket.Readable.push (node:internal/streams/readable:390:5)
    at TCP.onStreamRead (node:internal/stream_base_commons:191:23)
    at TCP.callbackTrampoline (node:internal/async_hooks:130:17)
@gianlazz gianlazz added the bug Something isn't working label May 26, 2024
@gianlazz gianlazz linked a pull request May 26, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant