Created attachment 10648 [details] Configuration of kelvin import When POSTing a user via Kelvin without a name, but a valid template provided, Code 500 is returned and a TypeError occurs while generating the username: Request: { "school": "https://example.com/ucsschool/kelvin/v1/schools/dummy", "firstname": "Klaftan", "lastname": "Stringulinski", "record_uid": "stringulinski3000", "roles": [ "https://example.com/ucsschool/kelvin/v1/roles/teacher" ], "schools": [ "https://example.com/ucsschool/kelvin/v1/schools/dummy" ] } Error: 2021-03-15 14:20:28 ERROR Exception in ASGI application Traceback (most recent call last): File "/kelvin/venv/lib/python3.8/site-packages/uvicorn/protocols/http/h11_impl.py", line 389, in run_asgi result = await app(self.scope, self.receive, self.send) File "/kelvin/venv/lib/python3.8/site-packages/uvicorn/middleware/proxy_headers.py", line 45, in __call__ return await self.app(scope, receive, send) File "/kelvin/venv/lib/python3.8/site-packages/fastapi/applications.py", line 140, in __call__ await super().__call__(scope, receive, send) File "/kelvin/venv/lib/python3.8/site-packages/starlette/applications.py", line 134, in __call__ await self.error_middleware(scope, receive, send) File "/kelvin/venv/lib/python3.8/site-packages/starlette/middleware/errors.py", line 178, in __call__ raise exc from None File "/kelvin/venv/lib/python3.8/site-packages/starlette/middleware/errors.py", line 156, in __call__ await self.app(scope, receive, _send) File "/kelvin/venv/lib/python3.8/site-packages/starlette/exceptions.py", line 73, in __call__ raise exc from None File "/kelvin/venv/lib/python3.8/site-packages/starlette/exceptions.py", line 62, in __call__ await self.app(scope, receive, sender) File "/kelvin/venv/lib/python3.8/site-packages/starlette/routing.py", line 590, in __call__ await route(scope, receive, send) File "/kelvin/venv/lib/python3.8/site-packages/starlette/routing.py", line 208, in __call__ await self.app(scope, receive, send) File "/kelvin/venv/lib/python3.8/site-packages/starlette/routing.py", line 41, in app response = await func(request) File "/kelvin/venv/lib/python3.8/site-packages/fastapi/routing.py", line 127, in app raw_response = await dependant.call(**values) File "/kelvin/kelvin-api/ucsschool/kelvin/routers/user.py", line 653, in create user = await user_importer.determine_add_modify_action(user) File "/kelvin/ucs-school-import/modules/ucsschool/importer/mass_import/user_import.py", line 273, in determine_add_modify_action return self.prepare_imported_user(imported_user, None) File "/kelvin/ucs-school-import/modules/ucsschool/importer/mass_import/user_import.py", line 252, in prepare_imported_user imported_user.prepare_all(new_user=not old_user) File "/kelvin/ucs-school-import/modules/ucsschool/importer/models/import_user.py", line 530, in prepare_all self.prepare_attributes(new_user) File "/kelvin/ucs-school-import/modules/ucsschool/importer/models/import_user.py", line 544, in prepare_attributes self.make_username() File "/kelvin/ucs-school-import/modules/ucsschool/importer/models/import_user.py", line 864, in make_username self.name = self.format_from_scheme("username", self.username_scheme) File "/kelvin/ucs-school-import/modules/ucsschool/importer/models/import_user.py", line 1300, in format_from_scheme res: Union[bytes, str] = self.prop._replace(scheme, all_fields) File "/kelvin/venv/lib/python3.8/site-packages/univention/admin/__init__.py", line 279, in _replace return pattern_replace(copy.copy(res), object) File "/kelvin/venv/lib/python3.8/site-packages/univention/admin/__init__.py", line 114, in pattern_replace value = modify_text(value, global_commands) File "/kelvin/venv/lib/python3.8/site-packages/univention/admin/__init__.py", line 62, in modify_text text = text.replace(umlaut, code) TypeError: a bytes-like object is required, not 'str'
Same problem with kelvin 1.2 in my test environment. Using the example of the documentation regarding create fails with that traceback.
QA should check the following: on single- AND multi-server environment: - test manually without specified name (as shown in bug description) - test manually with specified name (with and without umlauts) - execute kelvin-api/tests/test_route_user.py::test_create_without_username - also check the other kelvin-api/tests - build docker container - code review
Fix implemented on twenzel/kelvin/kelvin_type_error with commits 7da737306 Bug #52925: fixed create and modify (needed bytestring list) 27239aca4 Bug #52878: migrate changes from ucs-branch Changes in the username_handler had to be made due to fixing the initial problem revealed another bug causing a TypeError in Tuple_to_LDAPMod(). When reproducing the error the given kelvin.json in the bug description must be adjusted (mapped_udm_properties, maildomain...) Behavior can be tested with kelvin-api/tests/test_route_user.py::test_create_without_username
QA → leaving resolved for code review of 27239aca4 Bug #52878: migrate changes from ucs-branch After that: → merge → create new app version → build for test appcenter on single- AND multi-server environment: - test manually without specified name (as shown in bug description) - test manually with specified name (with and without umlauts) OK execute kelvin-api/tests/test_route_user.py::test_create_without_username DOING also check the other kelvin-api/tests OK build docker container OK code review
DOING also check the other kelvin-api/tests → this was already DONE, the tests pass on my vm
The Docker images was build and push to the registry. docker-upload.software-univention.de/ucsschool-kelvin-rest-api:1.4.2 (f88b30fadc14) The apps ini for version 1.4.2 was adapted to use that image.
QA -> All OK -> Verify OK Tests pass in Jenkins OK Container was built OK Merge without conflicts OK Changelog entries
UCS@school Kelvin REST API 1.4.2 has been released. http://appcenter.software-univention.de/univention-repository/4.4/maintained/component/ucsschool-kelvin-rest-api_20210518142444/README_UPDATE_DE If this error occurs again, please clone this bug.