From 3f89f1ecc80a5e037b820f1bfd30e7bbc2137e38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Szulc?= Date: Wed, 31 Jul 2024 12:09:25 +0200 Subject: [PATCH 1/2] Fix error with ldap sync --- src/ralph/accounts/management/commands/ldap_sync.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ralph/accounts/management/commands/ldap_sync.py b/src/ralph/accounts/management/commands/ldap_sync.py index 05e58af204..83e32995a6 100644 --- a/src/ralph/accounts/management/commands/ldap_sync.py +++ b/src/ralph/accounts/management/commands/ldap_sync.py @@ -274,6 +274,12 @@ def populate_users(self): """Load users from ldap and populate them. Returns number of users.""" synced = 0 for user_dn, ldap_dict in self._get_users(): + if ldap_dict.get('c'): + try: + ldap_dict['c'] = [v.decode('utf-8') for v in ldap_dict['c']] + except UnicodeDecodeError: + logger.error("Can't decode country %s for user %s", ldap_dict['c'], user_dn) + continue _truncate('sn', 'last_name', ldap_dict) user = self._create_or_update_user(user_dn, ldap_dict) self.nested_groups.handle(user) From d701077e7f47addc8851811c77ccdcc90b2c9a44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Szulc?= Date: Wed, 31 Jul 2024 12:11:13 +0200 Subject: [PATCH 2/2] Fix flake --- src/ralph/accounts/management/commands/ldap_sync.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ralph/accounts/management/commands/ldap_sync.py b/src/ralph/accounts/management/commands/ldap_sync.py index 83e32995a6..1e619aac65 100644 --- a/src/ralph/accounts/management/commands/ldap_sync.py +++ b/src/ralph/accounts/management/commands/ldap_sync.py @@ -278,7 +278,11 @@ def populate_users(self): try: ldap_dict['c'] = [v.decode('utf-8') for v in ldap_dict['c']] except UnicodeDecodeError: - logger.error("Can't decode country %s for user %s", ldap_dict['c'], user_dn) + logger.error( + "Can't decode country %s for user %s", + ldap_dict['c'], + user_dn + ) continue _truncate('sn', 'last_name', ldap_dict) user = self._create_or_update_user(user_dn, ldap_dict)