Bug 52927 - ValueError in Kelvin 1.4.0 in validator initialization code
ValueError in Kelvin 1.4.0 in validator initialization 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
Tobias Wenzel
:
: 52930 (view as bug list)
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2021-03-16 17:03 CET by Daniel Tröder
Modified: 2021-03-18 11:58 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:03:29 CET
As the UCRV ucsschool/validation/logging/backupcount is now copied from the host into the Docker container, it can will be set to an empty string when unset in the host.

-----------------------------------------------------------------------------
/kelvin # ucr dump | grep validation
ucsschool/validation/logging/backupcount: 
-----------------------------------------------------------------------------
/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/__init__.py", line 34, in <module>
    from .computer import *  # noqa: F401, F403
  File "/kelvin/ucs-school-lib/modules/ucsschool/lib/models/computer.py", line 50, in <module>
    from .base import MultipleObjectsError, RoleSupportMixin, SuperOrdinateType, UCSSchoolHelperAbstractClass
  File "/kelvin/ucs-school-lib/modules/ucsschool/lib/models/base.py", line 51, in <module>
    from .validator import validate
  File "/kelvin/ucs-school-lib/modules/ucsschool/lib/models/validator.py", line 69, in <module>
    backup_count = int(ucr.get("ucsschool/validation/logging/backupcount", 60))
ValueError: invalid literal for int() with base 10: ''
-----------------------------------------------------------------------------

Handle an empty value for the UCRV ucsschool/validation/logging/backupcount.
Comment 1 Daniel Tröder univentionstaff 2021-03-16 17:16:26 CET
I just noticed that the above code with int() isn't the most common in the git repo. But without conversion to int the code would just crash in the Python logging library code.

[feature/kelvin ecb70fb38] Bug #52927: fix ValueError for empty UCRV
Comment 2 Tobias Wenzel univentionstaff 2021-03-17 09:14:40 CET
*** Bug 52928 has been marked as a duplicate of this bug. ***
Comment 3 Tobias Wenzel univentionstaff 2021-03-17 09:24:34 CET
If the ucr-v ucsschool/validation/logging/backupcount is not set, this will stil raise an error.

/kelvin/ucs-school-lib # 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/__init__.py", line 37, in <module>
    from .school import *
  File "/kelvin/ucs-school-lib/modules/ucsschool/lib/models/school.py", line 63, in <module>
    from .base import RoleSupportMixin, UCSSchoolHelperAbstractClass
  File "/kelvin/ucs-school-lib/modules/ucsschool/lib/models/base.py", line 67, in <module>
    from .validator import validate
  File "/kelvin/ucs-school-lib/modules/ucsschool/lib/models/validator.py", line 65, in <module>
    backup_count = int(ucr.get("ucsschool/validation/logging/backupcount").strip() or 60)
AttributeError: 'NoneType' object has no attribute 'strip'


I already have a fix (because I did QA for 52928 first).
In 4.4 the code is also wrong.


[twenzel/4.4/52930_attribute_error] b949561c5 Bug #52930: fix attribute error

[twenzel/kelvin/52930_attribute_error] 89a0c3044 Bug 52930: fix attribute error
Comment 4 Daniel Tröder univentionstaff 2021-03-17 09:25:41 CET
*** Bug 52930 has been marked as a duplicate of this bug. ***
Comment 5 Daniel Tröder univentionstaff 2021-03-17 09:27:35 CET
The code change does not work for an unset UCRV.
The UCR behavior seems erratic in Kelvin, will investigate separately.

Fixed for now:

[feature/kelvin 45a197f6d] Bug #52927: fix AttributeError for unset UCRV
Comment 6 Daniel Tröder univentionstaff 2021-03-17 09:39:12 CET
I made the same change in the 4.4 branch. It is not strictly necessary there, but doesn't hurt either and will make syncing the branches easier.

[4.4 0f6980b89] Bug #52927: sync code to feature/kelvin
Comment 7 Tobias Wenzel univentionstaff 2021-03-17 09:42:53 CET
QA → All OK → Verify


Thanks!