Skip to content

Admin delete-user destroys profile data on a path that then fails #653

Closed

Description

@thinkclay

What happens

routes/office-users.ts:165-175, the admin delete-user cascade:

await supabaseAdmin.schema("core").from("user_skills").delete().eq("user_id", id);
await supabaseAdmin.from("user_certifications").delete().eq("user_id", id);
await supabaseAdmin.from("work_experience").delete().eq("user_id", id);
await supabaseAdmin.from("education").delete().eq("user_id", id);
await supabaseAdmin.from("applications").delete().eq("user_id", id);
await supabaseAdmin.from("reviews").delete().eq("user_id", id);
await supabaseAdmin.from("organization_members").delete().eq("user_id", id);
await supabaseAdmin.schema("core").from("profile").delete().eq("user_id", id);

.schema("core") applies to the statement it is written on. Every call after the first addresses public.

table exists in so the delete
user_certifications core only targets public — fails
applications core only targets public — fails
reviews core only targets public — fails
work_experience nowhere (core.user_experience) fails
education nowhere (core.user_education) fails
organization_members nowhere at all fails

No result is destructured, so every error is discarded. The endpoint deletes core.user_skills and core.profile, leaves the rest, and returns success.

Impact

An operator actioning a deletion request believes the data is gone. The user's certifications, job applications and reviews remain.

Acceptance

  • Every delete names its schema explicitly and an existing table
  • work_experience → core.user_experience, education → core.user_education; decide what organization_members was meant to be (org membership is modelled as core.role_assignments.scope_org_id)
  • Each delete's error is checked; the endpoint fails loudly rather than reporting success
  • A test deletes a seeded user with rows in every table and asserts none remain

Same root cause as the CCPA issue and #618. Guarded going forward by #651.

Activity

  1. added
    bug
    agent-ready
    on Aug 27, 2026
  2. thinkclay commented on Aug 27, 2026

    @thinkclay
    ContributorAuthor

    Correction: what I filed here was wrong

    I claimed the six broken deletes leave certifications, applications and reviews behind while the endpoint reports success. They do not. Every one of those tables cascades from core.users, and core.users cascades from auth.users. Verified in a rolled-back transaction:

     phase  | edu | skills | certs | apps
     BEFORE |   2 |      6 |     3 |    1
    DELETE 1
     AFTER  |   0 |      0 |     0 |    0
    

    I read the code and the catalogue and inferred the consequence instead of running it. The six statements are dead, but the deletion they appear to perform happens anyway.

    What is actually wrong is worse

    Ten references to core.users do not cascade — three NO ACTION, seven RESTRICT:

    NO ACTION  core.skill_evidence.verified_by
    NO ACTION  core.user_skills.verified_by
    NO ACTION  core.work_logs.verified_by_user_id
    RESTRICT   core.tasks.created_by_user_id
    RESTRICT   core.punchlists.created_by_user_id
    RESTRICT   core.organization_documents.created_by
    RESTRICT   core.organization_document_versions.uploaded_by
    RESTRICT   core.organization_document_shares.created_by
    RESTRICT   core.organization_folders.created_by
    RESTRICT   core.organization_locations.created_by
    

    So for any user who has verified a work log or created a task, the final delete fails — after the two hand-written deletes that do work have already run:

    delete from core.user_skills ...   -- succeeds
    delete from core.profile ...       -- succeeds
    delete from core.users ...         -- ERROR: violates foreign key constraint
                                       --        work_logs_verified_by_user_id_fkey
    

    There is no transaction. The operator is told "Failed to delete user profile" while that user's skills and personal details are already destroyed, and retrying does nothing more.

    Reproduced end to end against a live stack with user …0002 (18 tasks, 3 punchlists): old code returned 500 with the profile row gone; the fix returns 409 blockedBy: [{tasks:18},{punchlists:3}] with the profile intact.

    So the title should read "destroys data on a path that then fails", not "leaves data behind and reports success". Fixed in #663, which also stops treating an unreadable count as zero — the same measurement error that produced #652.

  3. changed the title [-]Admin delete-user leaves certifications, applications and reviews behind, and reports success[/-] [+]Admin delete-user destroys profile data on a path that then fails[/+] on Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Complianceagent-readybug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions