User deletion fails on resource_link_events due to NOT NULL constraint on user_id

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

When attempting to delete certain users (via API, web UI, or hard_delete), the deletion process returns 204 No Content but the user is not removed. Upon investigation, the background job Users::MigrateRecordsToGhostUserInBatchesWorker fails due to a NOT NULL constraint violation on the user_id column in the resource_link_events table.

The error in PostgreSQL logs:

ERROR:  null value in column "user_id" of relation "resource_link_events" violates not-null constraint
DETAIL: Failing row contains (id=..., ...)

Steps to reproduce:

  1. Have a user account that has participated in activities which generate resource_link_events entries (e.g., linked issues).
  2. Attempt to delete the user via API (DELETE /users/:id) or GitLab UI (both with and without hard_delete).
  3. The request returns 204, but the user is still present afterwards.
  4. Check admin/background_jobs/retries or PostgreSQL logs — error appears.

Expected behavior: User deletion should complete successfully, with all resource_link_events reassigned to the Ghost user (similar to how resource_iteration_events is handled after related bug fix).

Actual behavior: Deletion job fails due to the NOT NULL constraint on user_id, leaving the user undeleted.

Environment details:

  • GitLab version: 17.11.16
  • Installation type: Omnibus
  • Database: PostgreSQL 16.8
  • Deletion method: API & UI tested, both fail

Additional info: This appears to be the same class of problem as previously reported for resource_iteration_events, but affecting resource_link_events. Community report: https://forum.gitlab.com/t/error-message-in-postgresql-log-file-null-value-in-column-user-id-of-relation-resource-link-events-violates-not-null-constraint/122933

Edited by 🤖 GitLab Bot 🤖