Univention Bugzilla – Bug 20933
add get_int() for univention.config_registry.ConfigRegistry
Last modified: 2022-01-26 17:21:18 CET
Falls eine Zahl erwartet wird, aber eine Zeichenkette in einer UCR-Variablen gespeichert ist, wirft der folgende Code eine ValueError-Exception: cfgRegistry = ucr.ConfigRegistry() cfgRegistry.load() my_int = int( cfgRegistry.get( var, default )) Es sollte eine Funktion "get_int" geben, welche sicher eine Zahl oder den angegebenen "default" zurück gibt.
This issue has been filed against UCS 2.4. UCS 2.4 is out of maintenance and many UCS components have vastly changed in later releases. Thus, this issue is now being closed. If this issue still occurs in newer UCS versions, please use "Clone this bug". In this case please provide detailed information on how this issue is affecting you.
We still need a simple: def get_int(self, key, default=None): try: return int(self[key]) except (KeyError, ValueError): return default
We should also implement a unit test for this, probably in base/univention-config-registry/tests/test_backend.py
https://git.knut.univention.de/univention/ucs/-/merge_requests/221
Reopen: The merge request is not merged yet and the package not built.
Verified: * Code review: Ok * Package update: Ok * Functional test (python REPL): Ok * Test coverage: /var/univention/buildsystem2/logs/ucs_5.0-0-errata5.0-1/univention-config-registry_15.0.7-16A~5.0.0.202201260941.log.bz2 shows: tests/test_backend.py::TestConfigRegistry::test_get_int PASSED [ 3%] tests/test_backend.py::TestConfigRegistry::test_get_int_string[10-None-10] PASSED [ 3%] tests/test_backend.py::TestConfigRegistry::test_get_int_string[10-20-100] PASSED [ 3%] tests/test_backend.py::TestConfigRegistry::test_get_int_string[10-string-10] PASSED [ 3%] tests/test_backend.py::TestConfigRegistry::test_get_int_string[string-10-100] PASSED [ 3%] tests/test_backend.py::TestConfigRegistry::test_get_int_string[10-20-101] PASSED [ 4%] tests/test_backend.py::TestConfigRegistry::test_get_int_string[string-None-None] PASSED [ 4%] tests/test_backend.py::TestConfigRegistry::test_get_int_string[string-10-101] PASSED [ 4%] * Advisory: Ok
A run of https://jenkins.knut.univention.de:8181/job/UCS-5.0/job/UCS-5.0-1/job/ErrataValidation/ confirmed that advisory and metadata are consistent and the errata update can be released.
<https://errata.software-univention.de/#/?erratum=5.0x197>