# Bug OP-16322 - Cannot delete users who have favourite projects

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

## Open points

_No work packages_

## Details

| Attribute | Value |
| --- | --- |
| Date |  |
| Priority | Medium |
| Module |  |
| Target versions | 15.1.1 |
| Observed in versions | 15.0.0 |
| Sprint | 15.1.1 |
| Backlog bucket |  |
| Bug found in version (deprecated) | 15.0.x |
| 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 | Oliver Günther |
| 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.  As an admin, create a new user
    
2.  Login as that user and add any project to your favourites by clicking on the star in the top right of the project overview page
    
3.  As the admin, try to delete that user
    

### What is the buggy behavior?

*   You will see the notification that the user will be deleted in the background
    
*   the user will, in fact, never be deleted
    

### What is the expected behavior?

*   the user should be deleted
    

### Environment information

**OpenProject version**

_v15.0.1_

### Implementation remarks

The deletion fails due to a foreign key constraint on the favorite table. The fix here, really, is to simply remove all favourites for the user to be deleted in the delete principals job.

```ruby
Favorite.where(user: user).destroy_all
```

### Workaround

And this leads us to the workaround which is to login as that user, go to the index of favoured projects (/projects?query\_id=favored) and remove all of them there before deleting the user as an admin.
