# Bug OP-16434 - Error 500 when bulk editing work packages

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

## Open points

_No work packages_

## Details

| Attribute | Value |
| --- | --- |
| Date |  |
| Priority | Medium |
| Module | Modules and project features / Work packages |
| Target versions | 16.0.0 |
| Observed in versions | 15.1.0 |
| Sprint | 16.0.0 |
| Backlog bucket |  |
| Bug found in version (deprecated) | 15.1.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 |  |
| Product manager |  |
| Developers | Christophe Bliard |
| Designer |  |
| Ordered by |  |
| Signed off by |  |
| Interest by |  |

## Planning

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

## Costs

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

## Description

### Before filing a report

  - *I found this closed/rejected bug-report and commented but I got no reaction, hence opening a new one*
    
    <br>

    [*https://community.openproject.org/projects/openproject/work\_packages/59939*](https://community.openproject.org/projects/openproject/work_packages/59939)

### Steps to reproduce

1.  Select multiple work packages by holding down CTRL or SHIFT

2.  Right click one and edit work packages

3.  Change the start and end-date (it also happens when changing priority)

4.  Make sure there are multiple ckeditor in the form (because of multiple "long text" custom fields)

5.  Confirm with OK

### What is the buggy behavior?

  - The website throws and error 500 and doesn't update the work packages as intended

  - The error does not occur always, maybe 3 of 10 times. It can be reproduced

### What is the expected behavior?

1.  The website confirms the changes and navigates back to the work packages overview page

### **Logs**

``` Debuglog
{"log":"E, [2025-01-09T08:22:25.284821 #1067] ERROR -- : [f20acbcc-396f-49cf-805f-4f1b559a39a9] user=24 Attempted to update a stale object: WorkPackage.: Attempted to update a stale object: WorkPackage.\n","stream":"stdout","time":"2025-01-09T08:22:25.285220189Z"}
{"log":"D, [2025-01-09T08:22:25.284907 #1067] DEBUG -- : [f20acbcc-396f-49cf-805f-4f1b559a39a9] [ActiveRecord::StaleObjectError] Attempted to update a stale object: WorkPackage.: <clean stacktrace below>\n","stream":"stdout","time":"2025-01-09T08:22:25.285257063Z"}

Attempted to update a stale object: WorkPackage.: 
  app/services/base_services/write.rb:36:in 'persist'
  app/services/base_services/base_contracted.rb:64:in 'block in perform'
  app/models/journal/notification_configuration.rb:40:in 'with'
  app/services/shared/service_context.rb:67:in 'block in without_context_transaction'
  lib/open_project/locale_helper.rb:36:in 'with_locale_for'
  app/models/user.rb:534:in 'execute_as'
  app/services/shared/service_context.rb:66:in 'without_context_transaction'
  app/services/shared/service_context.rb:45:in 'block in in_mutex_context'
  lib/open_project/mutex.rb:71:in 'block in with_advisory_lock'
  lib/open_project/mutex.rb:69:in 'with_advisory_lock'
  lib/open_project/mutex.rb:63:in 'block in with_advisory_lock_transaction'
  lib/open_project/mutex.rb:62:in 'with_advisory_lock_transaction'
  app/services/shared/service_context.rb:44:in 'in_mutex_context'
  app/services/shared/service_context.rb:35:in 'in_context'
  app/services/base_services/base_contracted.rb:54:in 'service_context'
  app/services/base_services/base_contracted.rb:59:in 'perform'
  app/services/base_services/base_callable.rb:40:in 'block in call'
  app/services/concerns/with_reversible_state.rb:53:in 'assign_state'
  app/services/base_services/base_callable.rb:39:in 'call'
  app/services/work_packages/bulk/update_service.rb:37:in 'alter_work_package'
  app/services/work_packages/bulk/bulked_service.rb:65:in 'block in bulk'
  app/services/work_packages/bulk/bulked_service.rb:57:in 'bulk'
  app/services/work_packages/bulk/bulked_service.rb:48:in 'block in call'
  app/models/journal/notification_configuration.rb:62:in 'with_first'
  app/models/journal/notification_configuration.rb:45:in 'with'
  app/services/shared/service_context.rb:67:in 'block in without_context_transaction'
  lib/open_project/locale_helper.rb:36:in 'with_locale_for'
  app/models/user.rb:534:in 'execute_as'
  app/services/shared/service_context.rb:66:in 'without_context_transaction'
  app/services/work_packages/bulk/bulked_service.rb:47:in 'call'
  app/controllers/work_packages/bulk_controller.rb:47:in 'update'
```

There's a 3000+ line debug log attached.

### Analysis

The provided log file shows that there are two identical requests received by the server to do the bulk edit:

  - First one at 2025-01-09T08:22:25.012239
    
      - request\_id: 5ff253ae-d128-4fc8-8031-7b8ce53a61d4
    
      - status 302
    
      - succeeded at 2025-01-09T08:22:25.935842

  - Second one at 2025-01-09T08:22:25.017141
    
      - request\_id: f20acbcc-396f-49cf-805f-4f1b559a39a9
    
      - status 500
    
      - fails at 2025-01-09T08:22:25.382549

What happens is that the bulk edit page sent the 2 requests when "Submit" button was clicked, only the last request is taken into account for the frontend.

The server receives the 2 requests more or less at the same time. They try concurrently to edit the same data. One will work and return a 302 redirect to the work packages list, the other will fail with error 500 because of concurrent edit.

If the last one sent by the frontend is the one succeeding, it's fine. Otherwise it will show the 500 error. That's why the error does not always occur.

From a first analysis, it seems to happen because of ckeditor intercepting the submit event and then reemitting it, but in case there are multiple ckeditor (because of "long text" custom fields), the submission is done as many times as the number of ckeditor in the form.

For some reason, this error produces a 409 Conflict in development environment instead of a 500 Internal Server Error, and so it does not make a visible error on the frontend, which is why it cannot be visibly reproduced in development environment.

Also the server needs to use multiple workers and/or threads to be able to reproduce the issue.

### Screenshots and other files

*<img class="image_resized op-uc-image op-uc-image_inline" style="width:1053px;" src="/api/v3/attachments/262070/content">*

### Environment information

**OpenProject installation type**

  - Docker-compose installation on Debian 12, docker engine 27.3.1

**OpenProject version**

*v15.1*

**Browser**

- [x] Chrome
- [ ] Firefox
- [ ] Safari
- [ ] Mobile Safari
- [ ] Other (please specify)

**Operating System**

- [x] Windows
- [ ] Mac OS X
- [ ] Mobile iOS
- [ ] Mobile Android
- [ ] Linux (please specify distro)
- [ ] Chrome OS
- [ ] Other (please specify)

**Language**

*both German*
