Bug 52928 - NameError in Kelvin 1.4.0 in validator code
NameError in Kelvin 1.4.0 in validator code
Status: VERIFIED FIXED
Product: UCS@school
Classification: Unclassified
Component: Ucsschool-lib
UCS@school 4.4
Other Linux
: P5 normal (vote)
: ---
Assigned To: Daniel Tröder
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2021-03-16 17:20 CET by Daniel Tröder
Modified: 2021-03-17 09:19 CET (History)
1 user (show)

See Also:
What kind of report is it?: Bug Report
What type of bug is this?: 5: Major Usability: Impairs usability in key scenarios
Who will be affected by this bug?: 1: Will affect a very few installed domains
How will those affected feel about the bug?: 3: A User would likely not purchase the product
User Pain: 0.086
Enterprise Customer affected?:
School Customer affected?:
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number:
Bug group (optional):
Max CVSS v3 score:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Tröder univentionstaff 2021-03-16 17:20:39 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.
Comment 1 Daniel Tröder univentionstaff 2021-03-16 17:23:35 CET
[feature/kelvin c6207da2a] Bug #52928: fix ImportError
Comment 2 Tobias Wenzel univentionstaff 2021-03-17 09:11:18 CET
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.
Comment 3 Tobias Wenzel univentionstaff 2021-03-17 09:14:40 CET

*** This bug has been marked as a duplicate of bug 52927 ***
Comment 4 Tobias Wenzel univentionstaff 2021-03-17 09:19:01 CET
I did not mean to mark this as a duplicate but 52930.