# Bug SPAR-224 - Migration job WorkPackages::AutomaticMode::MigrateValuesJob not properly retried

Project: Stream Planning and Reporting
Status: tested
URL: https://community.openproject.org/work_packages/SPAR-224

## Open points

_No work packages_

## Details

| Attribute | Value |
| --- | --- |
| Date |  |
| Priority | Medium |
| Module |  |
| Target versions | 15.4.2 |
| Observed in versions | 15.4.0 |
| Bug found in version (deprecated) | 15.4.x |
| 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

### Steps to reproduce

1.  Have an OpenProject instance at version 15.3.2 or earlier

2.  Perform the upgrade to 15.4.0 or 15.4.1 while keeping a worker instance up and still running the previous version

3.  Go to the work packages list.

### What is the buggy behavior?

  - The migration job `WorkPackages::AutomaticMode::MigrateValuesJob` which is normally run after the upgrade to 15.4.0 was picked by the worker running the previous version and failed.
    
      - It fails with the error "NameError: uninitialized constant WorkPackages::AutomaticMode"
    
      - This can be verified in the rails console by running `GoodJob::Job.where(job_class: "WorkPackages::AutomaticMode::MigrateValuesJob").discarded`

  - Here are some side effects of having the migration not being run:
    
      - The work packages are almost all in automatic scheduling mode, as they should have been switched to manual scheduling mode.
    
      - For predecessor/successor relations, no lag has been set on them. This lag would prevent the successor to be rescheduled to earliest possible date when predecessor's dates are changed.

  - More important: when restarting the app, `config/initializers/retry_failed_jobs_with_name_error.rb` should have rescheduled it, but that did not work because it failed with error "NameError: uninitialized constant WorkPackages::AutomaticMode" and it looks up jobs with `.where("error LIKE ?", "NameError: uninitialized constant %Job")` which does not match the error.

### What is the expected behavior?

1.  The migration fails to be executed by a worker running on a previous version, that's expected. But it should then be retried correctly on restart. That's the expected behavior

2.  Running `GoodJob::Job.where(job_class: "WorkPackages::AutomaticMode::MigrateValuesJob").discarded` after the complete upgrade should return an empty array: when the job is picked up by an old worker, it's discarded and when the new worker starts, the initializer reenqueues it for retry.

### **Logs**

See <mention class="mention" data-id="62342" data-type="work_package" data-text="##62342">##62342</mention> where 2 users had this issue and reported some logs about the problem.

### Environment information

**OpenProject installation type**

  - Packaged installation

  - Docker All-in-one container

  - Docker-compose installation

**OpenProject version**

15.4.0 and 15.4.1
