Univention Bugzilla – Bug 52928
NameError in Kelvin 1.4.0 in validator code
Last modified: 2021-03-17 09:19:01 CET
/kelvin # python3 Python 3.8.8 (default, Mar 15 2021, 13:12:20) [GCC 9.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from ucsschool.lib.models.validator import validate Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/kelvin/ucs-school-lib/modules/ucsschool/lib/models/validator.py", line 84, in <module> def obj_to_dict(obj: UdmObject) -> Dict[str, Any]: NameError: name 'UdmObject' is not defined ---------------------------------------------------------------------------- 'UdmObject' isn't imported as the try-except-ImportError block hodes a circular import exception. When the try-except is removed it is revealed: ---------------------------------------------------------------------------- >>> from ucsschool.lib.models.validator import validate Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/kelvin/ucs-school-lib/modules/ucsschool/lib/models/validator.py", line 42, in <module> from .base import UdmObject File "/kelvin/ucs-school-lib/modules/ucsschool/lib/models/base.py", line 51, in <module> from .validator import validate ImportError: cannot import name 'validate' from partially initialized module 'ucsschool.lib.models.validator' (most likely due to a circular import) (/kelvin/ucs-school-lib/modules/ucsschool/lib/models/validator.py) ---------------------------------------------------------------------------- Fix the circular import, but keep the type hint.
[feature/kelvin c6207da2a] Bug #52928: fix ImportError
QA → All OK → Verify Code change → Looks good I could reproduce the error with your test code. After the fix, the import did not work on my machine because the ucr was not set. This is fixed in Bug 52928. After the fix everything worked as expected and the tests pass.
*** This bug has been marked as a duplicate of bug 52927 ***
I did not mean to mark this as a duplicate but 52930.