Bug 54981 - KeyError: 'objectType' when opening users/user module with OX connector app installed
KeyError: 'objectType' when opening users/user module with OX connector app i...
Status: CLOSED FIXED
Product: UCS
Classification: Unclassified
Component: UDM (Generic)
UCS 5.0
Other Linux
: P5 normal (vote)
: UCS 5.0-2-errata
Assigned To: Maximilian Janßen
Florian Best
:
: 55060 (view as bug list)
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2022-07-13 15:21 CEST by Florian Best
Modified: 2023-07-06 19:01 CEST (History)
1 user (show)

See Also:
What kind of report is it?: ---
What type of bug is this?: ---
Who will be affected by this bug?: ---
How will those affected feel about the bug?: ---
User Pain:
Enterprise Customer affected?:
School Customer affected?:
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number: 2022071321000383, 2022080821000408, 2023020921001058
Bug group (optional):
Max CVSS v3 score:
best: Patch_Available+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Florian Best univentionstaff 2022-07-13 15:21:48 CEST
Version: 5.0-2 errata345

Remark: I have a UCS 5.0-2 primary domain controller with the OX Connector app installed. When I open the UDM user module, I see the traceback. It occurs every time I open the module.

Error: 
Interner Server-Fehler in "udm/syntax/choices (users/user)".
Request: udm/syntax/choices (users/user)

Traceback (most recent call last):
  File "%PY3%/notifier/threads.py", line 80, in _run
    result = self._function()
  File "%PY3%/notifier/__init__.py", line 105, in __call__
    return self._function(*tmp, **self._kwargs)
  File "%PY3%/univention/management/console/modules/udm/udm_ldap.py", line 99, in _decorated
    return method(*args, **kwargs)
  File "%PY3%/univention/management/console/ldap.py", line 152, in _decorated
    result = func(*args, **kwargs)
  File "%PY3%/univention/management/console/modules/udm/__init__.py", line 1002, in _thread
    return read_syntax_choices(syntax, options, ldap_connection=ldap_connection, ldap_position=ldap_position)
  File "%PY3%/univention/management/console/modules/udm/udm_ldap.py", line 1353, in read_syntax_choices
    module = UDM_Module(choice['objectType'], ldap_connection=ldap_connection, ldap_position=ldap_position)
KeyError: 'objectType'

Role: domaincontroller_master
Comment 1 Florian Best univentionstaff 2022-07-13 15:24:58 CEST
udm settings/syntax list
DN: cn=oxContextSelect,cn=open-xchange,cn=custom attributes,cn=univention,dc=ox-conn,dc=intranet
  addEmptyValue: TRUE
  base: None
  description: Select OX context objects
  filter: objectClass=oxContext
  ldapattribute: cn
  ldapvalue: oxContextIDNum
  name: oxContextSelect
  value: None
  viewonly: FALSE

Reproducer:
curl 'https://Administrator:univention@demo.univention.de/univention/command/udm/syntax/choices' \
  -H 'Accept: application/json; q=1.0, text/html; q=0.3; */*; q=0.1' \
  -H 'Content-Type: application/json' \
  --data-raw '{"options":{"syntax":"LDAP_Search","options":{"syntax":"LDAP_Search","filter":"objectClass=oxContext","viewonly":false,"base":"","value":"oxContextIDNum","attributes":["cn"],"empty":true,"empty_end":false}},"flavor":"users/user"}'
Comment 2 Florian Best univentionstaff 2022-07-13 15:33:22 CEST
The reason is that LDAPSearch adds an item without the 'objectType' key when addEmptyValue or appendEmptyValue:

5887 »   »   if cls.addEmptyValue:
5888 »   »   »   choices.insert(0, {'id': '', 'label': ''}) 
5889 »   »   elif cls.appendEmptyValue:
5890 »   »   »   choices.append({'id': '', 'label': ''})

Patch is:

diff --git management/univention-management-console-module-udm/umc/python/udm/udm_ldap.py management/univention-management-console-module-udm/umc/python/udm/udm_ldap.py
index 34525cee10..be5473d33f 100644
--- management/univention-management-console-module-udm/umc/python/udm/udm_ldap.py
+++ management/univention-management-console-module-udm/umc/python/udm/udm_ldap.py
@@ -1350,12 +1350,16 @@ def read_syntax_choices(syn, options=None, ldap_connection=None, ldap_position=N
                if isinstance(syn, udm_syntax.LDAP_Search):
                        choices = []
                        for choice in syn.get_umc_choices(ldap_connection, options):
-                               module = UDM_Module(choice['objectType'], ldap_connection=ldap_connection, ldap_position=ldap_position)
-                               choice.update({
-                                       'module': 'udm',
-                                       'flavor': module.flavor,
-                                       'icon': 'udm-%s' % module.name.replace('/', '-'),
-                               })
+                               try:
+                                       module = UDM_Module(choice['objectType'], ldap_connection=ldap_connection, ldap_position=ldap_position)
+                               except KeyError:
+                                       pass
+                               else:
+                                       choice.update({
+                                               'module': 'udm',
+                                               'flavor': module.flavor,
+                                               'icon': 'udm-%s' % module.name.replace('/', '-'),
+                                       })
                                choices.append(choice)
                else:
                        choices = syn.get_choices(ldap_connection, options)
Comment 3 Florian Best univentionstaff 2022-08-02 15:44:02 CEST
*** Bug 55060 has been marked as a duplicate of this bug. ***
Comment 4 Maximilian Janßen univentionstaff 2022-08-10 12:07:26 CEST
Version: 5.0-2 errata352
Remark: whenever opeing Group Settings
Comment 5 Maximilian Janßen univentionstaff 2022-08-11 14:20:19 CEST
univention-management-console-module-udm.yaml
f9dfc722c6e3 | Bug #54981: yaml
c634ef88c7ea | Bug #54981: KeyError: 'objectType' when opening users/user module with OX connector app installed

univention-management-console-module-udm (10.0.2-3)
c634ef88c7ea | Bug #54981: KeyError: 'objectType' when opening users/user module with OX connector app installed
Comment 6 Florian Best univentionstaff 2022-08-15 18:46:39 CEST
OK: LDAP_Search syntax classes with addEmptyValue or appendEmptyValue work again and add empty values
OK: YAML