Description
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
- Use an SQL adapter (SQLite or Postgres).
- Create a user with a few preferences.
- Delete the user with
payload.delete. - 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
Activity