Skip to content

Commit

Permalink
Fix importing invalid dict from settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinVG207 committed Nov 29, 2023
1 parent f353a5a commit c6f6320
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
3 changes: 2 additions & 1 deletion umalauncher/horsium.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ def init_browser(self) -> RemoteWebDriver:
][0]
self.browser_name = browser_name

if browser_name == 'Chromium':
# Hack to convert override Chromium to Chrome
if browser_name == 'Other (Chromium)':
browser_name = 'Chrome'

browser_list = []
Expand Down
2 changes: 1 addition & 1 deletion umalauncher/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def __init__(self):
self.s_training_helper_table_scenario_presets = se.Setting(
"Training helper table scenario presets",
"Scenario-specific selected preset.",
{key: "Default" for key in constants.SCENARIO_DICT},
{str(key): "Default" for key in constants.SCENARIO_DICT},
se.SettingType.DICT,
priority=-1
)
Expand Down
16 changes: 15 additions & 1 deletion umalauncher/settings_elements.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import enum
from loguru import logger

class SettingType(enum.Enum):
UNDEFINED = "undefined"
Expand Down Expand Up @@ -41,7 +42,20 @@ def import_dict(self, settings_dict, keep_undefined=False):
priority=-2
))
continue
getattr(self, key).value = value

attribute = getattr(self, key)

if isinstance(attribute.value, dict):
true_keys = set(attribute.value.keys())
new_keys = set(value.keys())

if true_keys != new_keys:
logger.warning(f"Setting {key} has different keys in the new settings dict. Reverting to default.")
logger.warning(f"True keys: {true_keys}")
logger.warning(f"New keys: {new_keys}")
continue

attribute.value = value

def __repr__(self):
return str(self.to_dict())
Expand Down

0 comments on commit c6f6320

Please sign in to comment.