Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PICARD-2748: Add check for missing profile_id keys #2323

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions picard/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,11 @@ def _get_active_profile_settings(self):

def _get_profile_settings(self, profile_id):
if self.settings_override is None:
profile_settings = self.__qt_config.profiles[self.SETTINGS_KEY][profile_id]
# Set to None if profile_id not in profile settings
profile_settings = self.__qt_config.profiles[self.SETTINGS_KEY][profile_id] if profile_id in self.__qt_config.profiles[self.SETTINGS_KEY] else None
else:
profile_settings = self.settings_override[profile_id]
# Set to None if profile_id not in settings_override
profile_settings = self.settings_override[profile_id] if profile_id in self.settings_override else None
if profile_settings is None:
log.error("Unable to find settings for user profile '%s'", profile_id)
return {}
Expand Down
16 changes: 16 additions & 0 deletions test/test_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,22 @@ def test_settings_with_overrides(self):
self.assertEqual(self.config.setting[self.test_setting_1], False)
self.assertEqual(self.config.setting[self.test_setting_2], 99)

# Re-enable profile overrides and check that the saved settings still exist
# with invalid profile id in profile list
profiles = [
{
"position": 4,
"title": "Test Profile 4",
"enabled": True,
"id": "test_key_4",
}
]
profiles.extend(self.get_profiles(enabled=True))
self.config.setting.set_profiles_override(profiles)
self.assertEqual(self.config.setting[self.test_setting_0], "def")
self.assertEqual(self.config.setting[self.test_setting_1], False)
self.assertEqual(self.config.setting[self.test_setting_2], 99)

def test_config_option_rename(self):
from picard.config_upgrade import rename_option
self.config.setting[self.test_setting_0] = "abc"
Expand Down
Loading