Univention Bugzilla – Bug 48021
PostReadPyHook module loaded twice
Last modified: 2023-03-25 06:42:27 CET
The modules of PostReadPyHooks introduced in Bug #47221 are loaded twice: * in UserImport * in BaseReader That leads to a hook not being able to use super() in __init__, because the second time (for 'all_entries_read') the super class will have changed and the "self" won't be an instance of it anymore. Example: --------------------------------------------------------------------------- class PostProcessInputDataHook(PostReadPyHook): def __init__(self, *args, **kwargs): super(PostProcessInputDataHook, self).__init__(*args, **kwargs) --------------------------------------------------------------------------- 2018-10-19 10:56:46 INFO user_import.read_input:109 Done reading 5. user: ImportTeacher(name=None, school=None, dn=None) 2018-10-19 10:56:46 ERROR mass_import.import_users:117 super(type, obj): obj must be an instance or subtype of type Traceback (most recent call last): File "/usr/lib/pymodules/python2.7/ucsschool/importer/mass_import/mass_import.py", line 107, in import_users imported_users = user_import.read_input() File "/usr/lib/pymodules/python2.7/ucsschool/importer/mass_import/user_import.py", line 112, in read_input self.call_post_read_hook_all_entries_read(self.imported_users, self.errors) File "/usr/lib/pymodules/python2.7/ucsschool/importer/mass_import/user_import.py", line 136, in call_post_read_hook_all_entries_read self._post_read_pyhook_cache = pyloader.get_hook_objects(self.connection) File "/usr/lib/pymodules/python2.7/ucsschool/lib/pyhooks/pyhooks_loader.py", line 126, in get_hook_objects pyhook_objs = [pyhook_cls(*args, **kwargs) for pyhook_cls in self.get_hook_classes()] File "/usr/share/ucs-school-import/pyhooks/post_process_input_data.py", line 54, in __init__ super(PostProcessInputDataHook, self).__init__(*args, **kwargs) TypeError: super(type, obj): obj must be an instance or subtype of type
A common cache for running both methods (entry_read and all_entries_read) of PostReadPyHook modules is now used: f1e6e7b29 Bug #48021: retain stacktrace in traceback 1ac98ab73 Bug #48021: improve docstring fa1238ed1 Bug #48021: use common cache for PostReadPyHook modules for both methods (entry_read and all_entries_read) A workaround until this is released, is to use an old-style class "super" call: ------------------------------------------------------------------------- try: super(MyPostReadPyHook, self).__init__(*args, **kwargs) except TypeError: PostReadPyHook.__init__(self, *args, **kwargs) ------------------------------------------------------------------------- https://git.knut.univention.de/univention/components/ucsschool-hooks/blob/4.2/pyhooks/post_process_input_data.py#L54
PS: branch is dtroeder/48021_PostReadPyHook_module_loaded_twice
Fixed in code for Bug #48958. *** This bug has been marked as a duplicate of bug 48958 ***