project-pegaprox icon indicating copy to clipboard operation
project-pegaprox copied to clipboard

[Bug] Rolling an update back overwrites pegaprox/api/settings.py with the launcher, and the service no longer starts

Open gputier opened this issue 3 weeks ago • 4 comments

Describe the bug

POST /api/pegaprox/update/rollback with a backup made by the updater answers success: true. It replaces pegaprox/api/settings.py with a copy of pegaprox_multi_cluster.py, and restarts. After the restart PegaProx does not come up: ImportError: cannot import name 'bp' from 'pegaprox.api.settings'.

The rollback still looks for a single-file install. In rollback_pegaprox_update (pegaprox/api/settings.py):

current_dir = os.path.dirname(os.path.abspath(__file__))
current_backend = os.path.abspath(__file__)            # pegaprox/api/settings.py itself
current_frontend = os.path.join(current_dir, 'index.html')
...
for f in os.listdir(backup_path):
    if f.endswith('.py'):
        backup_backend = os.path.join(backup_path, f)
        break
...
shutil.copy2(backup_backend, current_backend)

The updater writes the backup as a tree: pegaprox/, web/ and static/ as directories, and pegaprox_multi_cluster.py, version.json and requirements.txt beside them. The only .py at the top of a backup is the launcher. So the launcher is copied over the module that holds the route. The frontend is not restored either: index.html is looked for at the top of the backup, and it is under web/.

Steps to Reproduce

  1. Start a container of ghcr.io/pegaprox/pegaprox-testing:latest and create the first admin.
  2. Make a backup the way the updater does (or run a real update): a directory config/backups/pegaprox_1.4.1_<timestamp>/ holding copies of pegaprox/, web/, static/, pegaprox_multi_cluster.py, version.json and requirements.txt.
  3. POST /api/pegaprox/update/rollback with {"backup": "pegaprox_1.4.1_<timestamp>"}.

What I got:

{"message":"Rolled back to pegaprox_1.4.1_20261110_120000. Server restarting...","restarting":true,"restored":["backend"],"success":true}
HTTP 200

Before the call, pegaprox/api/settings.py had 6791 lines (sha256 8ad3b81c...). After it, it had 273 lines and sha256 cb84579f..., the hash of pegaprox_multi_cluster.py. Then, at the restart:

  File "/app/pegaprox/api/__init__.py", line 21, in register_blueprints
    from pegaprox.api.settings import bp as settings_bp
ImportError: cannot import name 'bp' from 'pegaprox.api.settings' (/app/pegaprox/api/settings.py)

The container exited with code 1.

Expected behavior

The rollback puts back what the updater saved (pegaprox/, web/, static/ and the three files), or it refuses and says why. It never answers success after writing over a module of the running install.

Environment

  • PegaProx Version: 1.4.1 (Testing, build of 10 Nov 2026, image ghcr.io/pegaprox/pegaprox-testing:latest). The same lines are on main, so the 1.4.1 release has it too.
  • Installation Method: Docker
  • OS: the image's own (python:3.12-slim)
  • Browser: not involved, the route was called with curl
  • Behind Reverse Proxy? No
  • UI? not involved

Logs

ImportError: cannot import name 'bp' from 'pegaprox.api.settings' (/app/pegaprox/api/settings.py)

Screenshots

None.

I can open a PR for this if the direction suits you. It would restore the saved directories and files from the backup tree, with a test that runs the route against a backup laid out by the updater. Do you want the rollback to go through update.sh instead? That script already restores web/ with its language files.

Checklist

  • [x] I have searched existing issues to make sure this is not a duplicate
  • [x] I am using the latest version of PegaProx
  • [x] I've put enough in here that someone can start on it without asking me three questions first
  • [x] I understand PegaProx is maintained by volunteers in their free time. Nobody is on call, and writing URGENT doesn't get anyone out of bed 🪄

gputier avatar Nov 10 '26 15:11 gputier

Thanks for tracing this through. I can confirm it on Testing: the updater writes the backup as a tree (pegaprox/, web/, static/ plus the launcher, version.json and requirements.txt), while rollback_pegaprox_update still copies the first top-level .py over its own settings.py and looks for index.html at the top. Whether the rollback should restore the tree itself or go through update.sh is a call for the maintainers, so I've flagged this one for them together with your offer.

Jan-Philipp

Ghoszbust3r avatar Nov 10 '26 16:11 Ghoszbust3r

Thanks Jan-Philipp. To help the maintainers decide, here is what the "restore the tree itself" option looks like on a branch: https://github.com/gputier/project-pegaprox/tree/fix/update-rollback-restores-the-tree (one commit on Testing 99df4577, pegaprox/api/settings.py and one test file).

What it does:

  • every file under pegaprox/, web/ and static/ of the backup goes back to the same path under the install directory, along with pegaprox_multi_cluster.py, version.json and requirements.txt;
  • a backup without the launcher or without pegaprox/api/settings.py is refused with a 400 and nothing is written. Today such a backup answers "Rolled back" with restored: [];
  • the answer keeps its two names, backend and frontend.

What it does not do, and where update.sh may be the better road:

  • it copies back, it does not delete. A file that only the newer release has stays in place (there is a test that pins this), so the tree can be a mix of two releases;
  • it does not reinstall the Python requirements of the older release;
  • a copy that fails halfway leaves a partial restore. It is not atomic.

Tests, through the route, on a temporary install tree: 10 passed with the change, 10 failed on Testing (the launcher lands on settings.py, the page stays the new one).

I will not open a PR until you have chosen. If you go through update.sh, the tests may still be of use.

gputier avatar Nov 11 '26 10:11 gputier

Thanks for writing that out. Restoring the tree the updater backed up, and refusing a backup without the launcher or settings.py, is the way we want it. We're putting that fix in on Testing along those lines together with today's other follow-ups.

Marcus

mkellermann97 avatar Nov 11 '26 14:11 mkellermann97

1.5.0 is out with this fixed, a rollback no longer overwrites settings.py with the launcher. Closing.

Nico

MrMasterbay avatar Nov 15 '26 02:11 MrMasterbay