immich-app / immich

High performance self-hosted photo and video management solution.
https://immich.app
GNU Affero General Public License v3.0
52.05k stars 2.76k forks source link

[BUG] "asset_faces" violates foreign key constraint #4637

Closed travelr closed 1 year ago

travelr commented 1 year ago

The bug

Hi,

the face recognition job is causing foreign key constraint violations with the table persons

[Nest] 8  - 10/25/2023, 4:42:29 AM   ERROR [JobService] Unable to run job handler (recognizeFaces/recognize-faces): QueryFailedError: insert or update on table "asset_faces" violates foreign key constraint "FK_95ad7106dd7b484275443f580f9"
[Nest] 8  - 10/25/2023, 4:42:29 AM   ERROR [JobService] QueryFailedError: insert or update on table "asset_faces" violates foreign key constraint "FK_95ad7106dd7b484275443f580f9"
    at PostgresQueryRunner.query (/usr/src/app/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:211:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async InsertQueryBuilder.execute (/usr/src/app/node_modules/typeorm/query-builder/InsertQueryBuilder.js:106:33)
    at async SubjectExecutor.executeInsertOperations (/usr/src/app/node_modules/typeorm/persistence/SubjectExecutor.js:260:42)
    at async SubjectExecutor.execute (/usr/src/app/node_modules/typeorm/persistence/SubjectExecutor.js:92:9)
    at async EntityPersistExecutor.execute (/usr/src/app/node_modules/typeorm/persistence/EntityPersistExecutor.js:140:21)
    at async PersonService.handleRecognizeFaces (/usr/src/app/dist/domain/person/person.service.js:222:13)
    at async /usr/src/app/dist/domain/job/job.service.js:108:37
    at async Worker.processJob (/usr/src/app/node_modules/bullmq/dist/cjs/classes/worker.js:350:28)
    at async Worker.retryIfFailed (/usr/src/app/node_modules/bullmq/dist/cjs/classes/worker.js:535:24)
[Nest] 8  - 10/25/2023, 4:42:29 AM   ERROR [JobService] Object:
{
  "id": "2d060d78-2e2c-40c3-8d25-5d9cb74dadb8"
}

[Nest] 8  - 10/25/2023, 4:42:29 AM   ERROR [JobService] Unable to run job handler (recognizeFaces/recognize-faces): QueryFailedError: insert or update on table "asset_faces" violates foreign key constraint "FK_95ad7106dd7b484275443f580f9"
[Nest] 8  - 10/25/2023, 4:42:29 AM   ERROR [JobService] QueryFailedError: insert or update on table "asset_faces" violates foreign key constraint "FK_95ad7106dd7b484275443f580f9"
    at PostgresQueryRunner.query (/usr/src/app/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:211:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async InsertQueryBuilder.execute (/usr/src/app/node_modules/typeorm/query-builder/InsertQueryBuilder.js:106:33)
    at async SubjectExecutor.executeInsertOperations (/usr/src/app/node_modules/typeorm/persistence/SubjectExecutor.js:260:42)
    at async SubjectExecutor.execute (/usr/src/app/node_modules/typeorm/persistence/SubjectExecutor.js:92:9)
    at async EntityPersistExecutor.execute (/usr/src/app/node_modules/typeorm/persistence/EntityPersistExecutor.js:140:21)
    at async PersonService.handleRecognizeFaces (/usr/src/app/dist/domain/person/person.service.js:222:13)
    at async /usr/src/app/dist/domain/job/job.service.js:108:37
    at async Worker.processJob (/usr/src/app/node_modules/bullmq/dist/cjs/classes/worker.js:350:28)
    at async Worker.retryIfFailed (/usr/src/app/node_modules/bullmq/dist/cjs/classes/worker.js:535:24)
[Nest] 8  - 10/25/2023, 4:42:29 AM   ERROR [JobService] Object:
{
  "id": "6a994937-d9e0-4f59-b015-b975ca547f32"
}

[Nest] 8  - 10/25/2023, 4:42:29 AM   ERROR [JobService] Unable to run job handler (recognizeFaces/recognize-faces): QueryFailedError: insert or update on table "asset_faces" violates foreign key constraint "FK_95ad7106dd7b484275443f580f9"
[Nest] 8  - 10/25/2023, 4:42:29 AM   ERROR [JobService] QueryFailedError: insert or update on table "asset_faces" violates foreign key constraint "FK_95ad7106dd7b484275443f580f9"
    at PostgresQueryRunner.query (/usr/src/app/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:211:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async InsertQueryBuilder.execute (/usr/src/app/node_modules/typeorm/query-builder/InsertQueryBuilder.js:106:33)
    at async SubjectExecutor.executeInsertOperations (/usr/src/app/node_modules/typeorm/persistence/SubjectExecutor.js:260:42)
    at async SubjectExecutor.execute (/usr/src/app/node_modules/typeorm/persistence/SubjectExecutor.js:92:9)
    at async EntityPersistExecutor.execute (/usr/src/app/node_modules/typeorm/persistence/EntityPersistExecutor.js:140:21)
    at async PersonService.handleRecognizeFaces (/usr/src/app/dist/domain/person/person.service.js:222:13)
    at async /usr/src/app/dist/domain/job/job.service.js:108:37
    at async Worker.processJob (/usr/src/app/node_modules/bullmq/dist/cjs/classes/worker.js:350:28)
    at async Worker.retryIfFailed (/usr/src/app/node_modules/bullmq/dist/cjs/classes/worker.js:535:24)
[Nest] 8  - 10/25/2023, 4:42:29 AM   ERROR [JobService] Object:
{
  "id": "d63a0967-f74c-4c29-a87e-ea936a8d51fa"
}

The OS that Immich Server is running on

Ubuntu 22

Version of Immich Server

v1.8.2.1

Version of Immich Mobile App

latest

Platform with the issue

Your docker-compose.yml content

-

Your .env content

-

Reproduction steps

Reproduction is unclear, in previous runs facial recognition worked. Various faces are already identified in the database.

Now after adding a bunch of photos to the external library, facial recognition always fails with the constraint violation.

Additional information

Please advise what further information is required.

jrasm91 commented 1 year ago

There is a current limitation where the same person cannot appear in the same photo not than once, otherwise it throws this error. This is a limitation we're looking to remove soon.

jrasm91 commented 1 year ago

This actually should be fixed once #4474 is released.

travelr commented 1 year ago

This issue still occurs with some photos using version 1.8.4. But the errors are now occurring less compared to 1.8.2

[Nest] 7  - 11/05/2023, 10:00:47 AM   ERROR [JobService] Unable to run job handler (recognizeFaces/recognize-faces): QueryFailedError: insert or update on table "asset_faces" violates foreign key constraint "FK_95ad7106dd7b484275443f580f9"
[Nest] 7  - 11/05/2023, 10:00:47 AM   ERROR [JobService] QueryFailedError: insert or update on table "asset_faces" violates foreign key constraint "FK_95ad7106dd7b484275443f580f9"
    at PostgresQueryRunner.query (/usr/src/app/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:211:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async InsertQueryBuilder.execute (/usr/src/app/node_modules/typeorm/query-builder/InsertQueryBuilder.js:106:33)
    at async SubjectExecutor.executeInsertOperations (/usr/src/app/node_modules/typeorm/persistence/SubjectExecutor.js:260:42)
    at async SubjectExecutor.execute (/usr/src/app/node_modules/typeorm/persistence/SubjectExecutor.js:92:9)
    at async EntityPersistExecutor.execute (/usr/src/app/node_modules/typeorm/persistence/EntityPersistExecutor.js:140:21)
    at async PersonService.handleRecognizeFaces (/usr/src/app/dist/domain/person/person.service.js:194:13)
    at async /usr/src/app/dist/domain/job/job.service.js:108:37
    at async Worker.processJob (/usr/src/app/node_modules/bullmq/dist/cjs/classes/worker.js:350:28)
    at async Worker.retryIfFailed (/usr/src/app/node_modules/bullmq/dist/cjs/classes/worker.js:535:24)
[Nest] 7  - 11/05/2023, 10:00:47 AM   ERROR [JobService] Object:
{
  "id": "02144ef9-fc32-4ebd-b78a-8fd1a5701db4"
}
}