# Bug OP-14226 - Copying project fails when work package with children is copied

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

## Open points

_No work packages_

## Details

| Attribute | Value |
| --- | --- |
| Date |  |
| Priority | Medium |
| Module |  |
| Target versions | 13.2.1 |
| Observed in versions | 13.2.0 |
| Sprint | 13.2.1 |
| Backlog bucket |  |
| Bug found in version (deprecated) | 13.2.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 | Oliver Günther |
| 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

These steps were tested in a fresh installation via the following.

``` bash
docker run --rm -p 8080:80 -e OPENPROJECT_HTTPS=false -it openproject/community:13
```

1.  Create a new project
2.  Create a work package called 'parent'
3.  Create a work package called 'child'
4.  Right click the 'child' and choose 'indent hierarchy'
5.  Select the child
6.  Set its 'work' field to 35h
7.  Set it's dates to some date in the past (here it was 25th Sep 2022 to 29th Sep 2022) with 'working days only' unchecked
8.  Copy the project

### What is the buggy behavior?

  - the project is copied (in the original example with missing work packages, in this one all work packages are actually copied, though\!)
  - finishes with error:
      - Work packages could not be (fully) copied.

### What is the expected behavior?

  - Copying should work without errors and copy all work packages

### Logs

``` text
# in app/services/work_packages/update_ancestors_service.rb:81
#   updated_ancestors.all? { |wp| wp.save(validate: false) }
#<ActiveRecord::StaleObjectError: Attempted to update a stale object: WorkPackage.>

Encountered an errors while trying to copy related objects for project '956': ["Work packages could not be (fully) copied."]
```

### Environment information

**OpenProject installation type**

- [x] Hosted cloud edition
- [ ] Packaged installation
    - What distribution?
- [x] Docker All-in-one container
- [ ] Docker-compose installation
- [ ] Other (please specify)

**OpenProject version**

*v13.2.0*
