Skip to content

Commit 63371be

Browse files
committed
Fix settings.py preservation during upgrade to maintain INSTALLED_APPS
During the upgrade process, settings.py was being overwritten with only the DATABASES section preserved, causing loss of INSTALLED_APPS and other configurations. This resulted in the 'aiScanner' app not being recognized after upgrade. Fixed by: - Improving the regex pattern to more accurately match only the DATABASES dictionary - Adding re.DOTALL flag to handle multi-line DATABASES configuration - Ensuring all other settings including INSTALLED_APPS are preserved during upgrade This resolves the RuntimeError about aiScanner.status_models.ScanStatusUpdate not having an explicit app_label.
1 parent 00885d2 commit 63371be

File tree

2 files changed

+19
-21
lines changed

2 files changed

+19
-21
lines changed

.idea/workspace.xml

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

plogical/upgrade.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2467,28 +2467,27 @@ def downloadAndUpgrade(versionNumbring, branch):
24672467
Upgrade.stdOut("Restoring configuration files...")
24682468
Upgrade.restoreCriticalFiles(backup_dir, backed_up_files)
24692469

2470-
## Copy settings file
2471-
2472-
settingsData = open(settingsFile, 'r').readlines()
2473-
2474-
DATABASESCHECK = 0
2470+
## Update settings file with database credentials while preserving other settings
2471+
2472+
# Read the current settings file (which was just restored from backup)
2473+
settingsData = open(settingsFile, 'r').read()
2474+
2475+
# Replace only the DATABASES section while keeping everything else (including INSTALLED_APPS)
2476+
import re
2477+
2478+
# More precise pattern to match the entire DATABASES dictionary including nested dictionaries
2479+
# This pattern looks for DATABASES = { ... } including the 'default' and 'rootdb' nested dicts
2480+
database_pattern = r'DATABASES\s*=\s*\{[^}]*\{[^}]*\}[^}]*\{[^}]*\}[^}]*\}'
2481+
2482+
# Replace the DATABASES section with our saved credentials
2483+
settingsData = re.sub(database_pattern, completDBString.strip(), settingsData, flags=re.DOTALL)
2484+
2485+
# Write back the updated settings
24752486
writeToFile = open(settingsFile, 'w')
2476-
2477-
for items in settingsData:
2478-
if items.find('DATABASES = {') > -1:
2479-
DATABASESCHECK = 1
2480-
2481-
if DATABASESCHECK == 0:
2482-
writeToFile.write(items)
2483-
2484-
if items.find('DATABASE_ROUTERS = [') > -1:
2485-
DATABASESCHECK = 0
2486-
writeToFile.write(completDBString)
2487-
writeToFile.write(items)
2488-
2487+
writeToFile.write(settingsData)
24892488
writeToFile.close()
24902489

2491-
Upgrade.stdOut('Settings file restored!')
2490+
Upgrade.stdOut('Settings file restored with database credentials!')
24922491

24932492
Upgrade.staticContent()
24942493

0 commit comments

Comments
 (0)