Skip to content

Preferences of a deleted user remain on SQL adapters #19242

Open

Description

@digitalwerber

Describe the Bug

On SQL adapters, deleting a user of an auth collection leaves that user's preferences in payload-preferences.

delete.ts and deleteByID.ts delete the document first and call deleteUserPreferences afterwards. Deleting the user row cascades to payload_preferences_rels, so the user condition no longer matches anything, and the preferences stay behind without a user. On MongoDB they are removed as expected.

Reversing the order would fix it, but on adapters without transactions (e.g. Cloudflare D1) a failing document delete would then already have removed the preferences, so this probably needs a decision on the intended behavior.

Link to the code that reproduces this issue

https://github.com/digitalwerber/payload/blob/repro/orphaned-preferences/test/collections-rest/delete-user-preferences.int.spec.ts (fails on SQLite and Postgres, passes on MongoDB)

Reproduction Steps

  1. Use an SQL adapter (SQLite or Postgres).
  2. Create a user with a few preferences.
  3. Delete the user with payload.delete.
  4. Query payload-preferences: the user's preferences are still there.

Which area(s) are affected?

area: core

Environment Info

payload: 4.0.0-beta.6
next: 16.4.2
node: 24.22.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

BugPayload OSSarea: core

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions