From 54fd81a87e2265c1eaeeae12cacbcd4d5b065ac2 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 15 Nov 2021 12:07:59 +0100 Subject: [PATCH] [displaymanager] Handle case where config file doesn't exist or has no key - If the config file doesn't exist, the dictionary is empty - If it **does** exist, it might not have key 'default_session' in it Either case should avoid a KeyError by using get() (or setdefault, in this context). Subsequent use of os.path.exists() is strange, since the value is a **group** (e.g. a dictionary) in the config file. Just check if it exists, and then fill something in. --- src/modules/displaymanager/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/modules/displaymanager/main.py b/src/modules/displaymanager/main.py index d9832730b..5b92ccf8d 100644 --- a/src/modules/displaymanager/main.py +++ b/src/modules/displaymanager/main.py @@ -859,7 +859,8 @@ class DMgreetd(DisplayManager): self.config_data['terminal'] = dict(vt = "next") - if not os.path.exists(self.config_data['default_session']): + default_session_group = self.config_data.get('default_session', None) + if not default_session_group: self.config_data['default_session'] = {} self.config_data['default_session']['user'] = self.greeter_user