# Bug OP-14427 - Users who booked unit costs cannot be deleted

Project: OpenProject
Status: closed
URL: https://community.openproject.org/work_packages/OP-14427

## Open points

_No work packages_

## Details

| Attribute | Value |
| --- | --- |
| Date |  |
| Priority | Medium |
| Module |  |
| Target versions | 13.3.1 |
| Observed in versions |  |
| Sprint | 13.3.1 |
| Backlog bucket |  |
| Bug found in version (deprecated) |  |
| Found in mobile app version |  |
| Follow-up feedback e-mail |  |
| Requires doc change | No |
| Accessibility | No |
| Pull preview |  |
| List |  |
| Labels |  |

## People

| Attribute | Value |
| --- | --- |
| Assignee |  |
| Accountable |  |
| Product manager |  |
| Developers |  |
| Designer |  |
| Ordered by |  |
| Signed off by |  |
| Interest by |  |

## Planning

| Attribute | Value |
| --- | --- |
| Relevance |  |

## Costs

| Attribute | Value |
| --- | --- |
| Votes |  |
| Work |  |
| Labor costs |  |

## Description

### Steps to reproduce

1.  Create a project
2.  Enable cost and time tracking
3.  Under administration -&gt; time and costs -&gt; cost types, create a default cost type
4.  Create a new non-admin user
5.  add user as project admin to project
6.  as the user, book any number of unit costs on a work package in the project
7.  as an admin
    1.  allow user deletion under admin -&gt; users -&gt; user settings
    2.  try to delete the user

### What is the buggy behavior?

*   the user is not deleted

### What is the expected behavior?

*   the user should be deleted

### Important note

### **Logs**

```text
/app/app/workers/principals/delete_job.rb:33:in `perform'
...
/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3/lib/active_record/connection_adapters/postgresql_adapter.rb:894:in `exec_params': PG::ForeignKeyViolation: ERROR:  update or delete on table "users" violates foreign key constraint "fk_rails_0d35f09506" on table "cost_entries" (ActiveRecord::InvalidForeignKey)
DETAIL:  Key (id)=(5) is still referenced from table "cost_entries".

/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3/lib/active_record/connection_adapters/postgresql_adapter.rb:894:in `exec_params': ERROR:  update or delete on table "users" violates foreign key constraint "fk_rails_0d35f09506" on table "cost_entries" (PG::ForeignKeyViolation)
DETAIL:  Key (id)=(5) is still referenced from table "cost_entries".
```

**OpenProject version**

_v13.3.0_
