From 63371be01197b21fd1fc7c09b782318f587df255 Mon Sep 17 00:00:00 2001 From: usmannasir Date: Fri, 8 Aug 2025 22:44:42 +0500 Subject: [PATCH] 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. --- .idea/workspace.xml | 3 +-- plogical/upgrade.py | 37 ++++++++++++++++++------------------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 3eb126154..79d3321fd 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -6,7 +6,6 @@ - diff --git a/plogical/upgrade.py b/plogical/upgrade.py index edd902724..066ab9d4c 100644 --- a/plogical/upgrade.py +++ b/plogical/upgrade.py @@ -2467,28 +2467,27 @@ CREATE TABLE `websiteFunctions_backupsv2` (`id` integer AUTO_INCREMENT NOT NULL Upgrade.stdOut("Restoring configuration files...") Upgrade.restoreCriticalFiles(backup_dir, backed_up_files) - ## Copy settings file - - settingsData = open(settingsFile, 'r').readlines() - - DATABASESCHECK = 0 + ## Update settings file with database credentials while preserving other settings + + # Read the current settings file (which was just restored from backup) + settingsData = open(settingsFile, 'r').read() + + # Replace only the DATABASES section while keeping everything else (including INSTALLED_APPS) + import re + + # More precise pattern to match the entire DATABASES dictionary including nested dictionaries + # This pattern looks for DATABASES = { ... } including the 'default' and 'rootdb' nested dicts + database_pattern = r'DATABASES\s*=\s*\{[^}]*\{[^}]*\}[^}]*\{[^}]*\}[^}]*\}' + + # Replace the DATABASES section with our saved credentials + settingsData = re.sub(database_pattern, completDBString.strip(), settingsData, flags=re.DOTALL) + + # Write back the updated settings writeToFile = open(settingsFile, 'w') - - for items in settingsData: - if items.find('DATABASES = {') > -1: - DATABASESCHECK = 1 - - if DATABASESCHECK == 0: - writeToFile.write(items) - - if items.find('DATABASE_ROUTERS = [') > -1: - DATABASESCHECK = 0 - writeToFile.write(completDBString) - writeToFile.write(items) - + writeToFile.write(settingsData) writeToFile.close() - Upgrade.stdOut('Settings file restored!') + Upgrade.stdOut('Settings file restored with database credentials!') Upgrade.staticContent()