Skip to content

Commit 753f4f0

Browse files
committed
Fix: Preserve new INSTALLED_APPS during upgrade by not overwriting settings.py
The issue was that restoreCriticalFiles was restoring the OLD settings.py from backup which didn't have new apps like 'aiScanner' in INSTALLED_APPS. Solution: - Modified restoreCriticalFiles to skip settings.py restoration - Keep the NEW settings.py from the fresh clone (which has aiScanner in INSTALLED_APPS) - Only update the DATABASES section with saved credentials from backup - This preserves all new app registrations while maintaining database connectivity This properly fixes the RuntimeError about aiScanner.status_models.ScanStatusUpdate not being in INSTALLED_APPS after upgrades.
1 parent 63371be commit 753f4f0

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

.idea/workspace.xml

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plogical/upgrade.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2360,6 +2360,11 @@ def backupCriticalFiles():
23602360
def restoreCriticalFiles(backup_dir, backed_up_files):
23612361
"""Restore critical configuration files after upgrade"""
23622362
for original_path, backup_path in backed_up_files.items():
2363+
# Skip settings.py - we'll handle it separately to preserve INSTALLED_APPS
2364+
if 'settings.py' in original_path:
2365+
Upgrade.stdOut(f"Skipping {original_path} - will be handled separately")
2366+
continue
2367+
23632368
try:
23642369
if os.path.isdir(backup_path):
23652370
if os.path.exists(original_path):
@@ -2463,31 +2468,31 @@ def downloadAndUpgrade(versionNumbring, branch):
24632468
if not Upgrade.executioner(command, command, 1):
24642469
Upgrade.stdOut(f"Warning: Failed to checkout branch {branch}, continuing with default branch")
24652470

2466-
# Restore all backed up configuration files
2471+
# Restore all backed up configuration files (except settings.py)
24672472
Upgrade.stdOut("Restoring configuration files...")
24682473
Upgrade.restoreCriticalFiles(backup_dir, backed_up_files)
24692474

2470-
## Update settings file with database credentials while preserving other settings
2475+
## Handle settings.py separately to preserve NEW INSTALLED_APPS while keeping old database credentials
24712476

2472-
# Read the current settings file (which was just restored from backup)
2477+
# Read the NEW settings file from the fresh clone (has new INSTALLED_APPS like 'aiScanner')
24732478
settingsData = open(settingsFile, 'r').read()
24742479

2475-
# Replace only the DATABASES section while keeping everything else (including INSTALLED_APPS)
2480+
# Replace only the DATABASES section with our saved credentials
24762481
import re
24772482

24782483
# More precise pattern to match the entire DATABASES dictionary including nested dictionaries
24792484
# This pattern looks for DATABASES = { ... } including the 'default' and 'rootdb' nested dicts
24802485
database_pattern = r'DATABASES\s*=\s*\{[^}]*\{[^}]*\}[^}]*\{[^}]*\}[^}]*\}'
24812486

2482-
# Replace the DATABASES section with our saved credentials
2487+
# Replace the DATABASES section with our saved credentials from before upgrade
24832488
settingsData = re.sub(database_pattern, completDBString.strip(), settingsData, flags=re.DOTALL)
24842489

24852490
# Write back the updated settings
24862491
writeToFile = open(settingsFile, 'w')
24872492
writeToFile.write(settingsData)
24882493
writeToFile.close()
24892494

2490-
Upgrade.stdOut('Settings file restored with database credentials!')
2495+
Upgrade.stdOut('Settings file updated with database credentials while preserving new INSTALLED_APPS!')
24912496

24922497
Upgrade.staticContent()
24932498

0 commit comments

Comments
 (0)