[BUG] After face is merged, new assets aren't recognized with new merged face #1138

Closed
opened 2026-02-05 00:36:17 +03:00 by OVERLORD · 1 comment
Owner

Originally created by @alextran1502 on GitHub (Jul 22, 2023).

Originally assigned to: @alextran1502 on GitHub.

The bug

After merging two or more faces together, uploading an asset with one of the two merge faces will cause FK constraint violation in database.

immich_microservices       | [Nest] 29  - 07/22/2023, 4:22:13 PM   DEBUG [FacialRecognitionService] 2 faces detected in upload/thumbs/e34fad52-d796-4180-b0b1-404aa8314056/97c96762-dc38-4d1c-834d-831c41792a94.jpeg
immich_postgres            | 2023-07-22 16:22:13.333 UTC [79] ERROR:  insert or update on table "asset_faces" violates foreign key constraint "FK_95ad7106dd7b484275443f580f9"
immich_postgres            | 2023-07-22 16:22:13.333 UTC [79] DETAIL:  Key (personId)=(f122754b-bd1f-4324-a887-b5d357c1f77b) is not present in table "person".
immich_postgres            | 2023-07-22 16:22:13.333 UTC [79] STATEMENT:  INSERT INTO "asset_faces"("assetId", "personId", "embedding", "imageWidth", "imageHeight", "boundingBoxX1", "boundingBoxY1", "boundingBoxX2", "boundingBoxY2") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING "imageWidth", "imageHeight", "boundingBoxX1", "boundingBoxY1", "boundingBoxX2", "boundingBoxY2"
immich_microservices       | [Nest] 29  - 07/22/2023, 4:22:13 PM   ERROR [JobService] Unable to run job handler: QueryFailedError: insert or update on table "asset_faces" violates foreign key constraint "FK_95ad7106dd7b484275443f580f9"
immich_microservices       | [Nest] 29  - 07/22/2023, 4:22:13 PM   ERROR [JobService] QueryFailedError: insert or update on table "asset_faces" violates foreign key constraint "FK_95ad7106dd7b484275443f580f9"
immich_microservices       |     at PostgresQueryRunner.query (/usr/src/app/src/driver/postgres/PostgresQueryRunner.ts:299:19)
immich_microservices       |     at processTicksAndRejections (node:internal/process/task_queues:95:5)
immich_microservices       |     at InsertQueryBuilder.execute (/usr/src/app/src/query-builder/InsertQueryBuilder.ts:163:33)
immich_microservices       |     at SubjectExecutor.executeInsertOperations (/usr/src/app/src/persistence/SubjectExecutor.ts:434:42)
immich_microservices       |     at SubjectExecutor.execute (/usr/src/app/src/persistence/SubjectExecutor.ts:137:9)
immich_microservices       |     at EntityPersistExecutor.execute (/usr/src/app/src/persistence/EntityPersistExecutor.ts:182:21)
immich_microservices       |     at FacialRecognitionService.handleRecognizeFaces (/usr/src/app/src/domain/facial-recognition/facial-recognition.services.ts:86:7)
immich_microservices       |     at /usr/src/app/src/domain/job/job.service.ts:115:27
immich_microservices       |     at Worker.processJob (/usr/src/app/node_modules/bullmq/src/classes/worker.ts:667:22)
immich_microservices       |     at Worker.retryIfFailed (/usr/src/app/node_modules/bullmq/src/classes/worker.ts:866:16)
immich_microservices       | [Nest] 29  - 07/22/2023, 4:22:13 PM   ERROR [JobService] Object:
immich_microservices       | {
immich_microservices       |   "id": "97c96762-dc38-4d1c-834d-831c41792a94",
immich_microservices       |   "source": "upload"
immich_microservices       | }
immich_microservices       | 

The OS that Immich Server is running on

Ubuntu

Version of Immich Server

v1.68.0

Version of Immich Mobile App

v.168.0

Platform with the issue

  • Server
  • Web
  • Mobile

Your docker-compose.yml content

Stock

Your .env content

Stock

Reproduction steps

1. Merge two faces.
2. Upload assets contain one of the two faces that get merged.
3. Observe error in logs

Additional information

No response

Originally created by @alextran1502 on GitHub (Jul 22, 2023). Originally assigned to: @alextran1502 on GitHub. ### The bug After merging two or more faces together, uploading an asset with one of the two merge faces will cause FK constraint violation in database. ```bash immich_microservices | [Nest] 29 - 07/22/2023, 4:22:13 PM DEBUG [FacialRecognitionService] 2 faces detected in upload/thumbs/e34fad52-d796-4180-b0b1-404aa8314056/97c96762-dc38-4d1c-834d-831c41792a94.jpeg immich_postgres | 2023-07-22 16:22:13.333 UTC [79] ERROR: insert or update on table "asset_faces" violates foreign key constraint "FK_95ad7106dd7b484275443f580f9" immich_postgres | 2023-07-22 16:22:13.333 UTC [79] DETAIL: Key (personId)=(f122754b-bd1f-4324-a887-b5d357c1f77b) is not present in table "person". immich_postgres | 2023-07-22 16:22:13.333 UTC [79] STATEMENT: INSERT INTO "asset_faces"("assetId", "personId", "embedding", "imageWidth", "imageHeight", "boundingBoxX1", "boundingBoxY1", "boundingBoxX2", "boundingBoxY2") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING "imageWidth", "imageHeight", "boundingBoxX1", "boundingBoxY1", "boundingBoxX2", "boundingBoxY2" immich_microservices | [Nest] 29 - 07/22/2023, 4:22:13 PM ERROR [JobService] Unable to run job handler: QueryFailedError: insert or update on table "asset_faces" violates foreign key constraint "FK_95ad7106dd7b484275443f580f9" immich_microservices | [Nest] 29 - 07/22/2023, 4:22:13 PM ERROR [JobService] QueryFailedError: insert or update on table "asset_faces" violates foreign key constraint "FK_95ad7106dd7b484275443f580f9" immich_microservices | at PostgresQueryRunner.query (/usr/src/app/src/driver/postgres/PostgresQueryRunner.ts:299:19) immich_microservices | at processTicksAndRejections (node:internal/process/task_queues:95:5) immich_microservices | at InsertQueryBuilder.execute (/usr/src/app/src/query-builder/InsertQueryBuilder.ts:163:33) immich_microservices | at SubjectExecutor.executeInsertOperations (/usr/src/app/src/persistence/SubjectExecutor.ts:434:42) immich_microservices | at SubjectExecutor.execute (/usr/src/app/src/persistence/SubjectExecutor.ts:137:9) immich_microservices | at EntityPersistExecutor.execute (/usr/src/app/src/persistence/EntityPersistExecutor.ts:182:21) immich_microservices | at FacialRecognitionService.handleRecognizeFaces (/usr/src/app/src/domain/facial-recognition/facial-recognition.services.ts:86:7) immich_microservices | at /usr/src/app/src/domain/job/job.service.ts:115:27 immich_microservices | at Worker.processJob (/usr/src/app/node_modules/bullmq/src/classes/worker.ts:667:22) immich_microservices | at Worker.retryIfFailed (/usr/src/app/node_modules/bullmq/src/classes/worker.ts:866:16) immich_microservices | [Nest] 29 - 07/22/2023, 4:22:13 PM ERROR [JobService] Object: immich_microservices | { immich_microservices | "id": "97c96762-dc38-4d1c-834d-831c41792a94", immich_microservices | "source": "upload" immich_microservices | } immich_microservices | ``` ### The OS that Immich Server is running on Ubuntu ### Version of Immich Server v1.68.0 ### Version of Immich Mobile App v.168.0 ### Platform with the issue - [X] Server - [ ] Web - [ ] Mobile ### Your docker-compose.yml content ```YAML Stock ``` ### Your .env content ```Shell Stock ``` ### Reproduction steps ```bash 1. Merge two faces. 2. Upload assets contain one of the two faces that get merged. 3. Observe error in logs ``` ### Additional information _No response_
OVERLORD added the 🗄️server label 2026-02-05 00:36:17 +03:00
Author
Owner

@alextran1502 commented on GitHub (Jul 22, 2023):

After further troubleshooting, the issue is from the out-of-sync Typesense database. We remove the old person but not updating all of the documents that relate to the old person in Typesense, leading to stale personId getting pulled from Typesense when we perform face matching.

@alextran1502 commented on GitHub (Jul 22, 2023): After further troubleshooting, the issue is from the out-of-sync Typesense database. We remove the old person but not updating all of the documents that relate to the old person in Typesense, leading to stale personId getting pulled from Typesense when we perform face matching.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: immich-app/immich#1138