Problem: Kelvin API throws Traceback

Problem

Using the Kelvin API ends with tracebacks like this:


2021-02-24 10:15:29 INFO  Going to create ImportStudent(name='Testuser1', school='DEMOSCHOOL', dn='uid=Testuser1,cn=schueler,cn=users,ou=DEMOSCHOOL,dc=supportschool,dc=univention,dc=intranet', old_dn=None) with {'$dn$': 'uid=Testuser1,cn=schueler,cn=users,ou=DEMOSCHOOL,dc=supportschool,dc=univention,dc=de', 'objectType': 'users/user', 'school': 'DEMOSCHOOL', 'name': 'Testuser1', 'schools': ['DEMOSCHOOL'], 'firstname': 'Hans', 'lastname': 'Wurst', 'birthday': None, 'email': 'HWurst@demo.univention.de', 'password': '********', 'disabled': False, 'school_classes': {'DEMOSCHOOL': ['10OS']}, 'ucsschool_roles': ['student:school:DEMOSCHOOL'], 'source_uid': 'Kelvin', 'record_uid': '29', 'display_name': 'Hans Wurst', 'type_name': 'Student', 'type': 'importStudent', 'action': 'A', 'entry_count': 0, 'udm_properties': {'overridePWHistory': True, 'overridePWLength': True}, 'input_data': [], 'old_user': None, 'in_hook': False, 'roles': ['student']}...
2021-02-24 10:15:29 INFO  172.17.42.1:35722 - "POST /ucsschool/kelvin/v1/users/ HTTP/1.1" 500
2021-02-24 10:15:29 ERROR Exception in ASGI application
Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/uvicorn/protocols/http/h11_impl.py", line 394, in run_asgi
    result = await app(self.scope, self.receive, self.send)
  File "/usr/lib/python3.8/site-packages/uvicorn/middleware/proxy_headers.py", line 45, in __call__
    return await self.app(scope, receive, send)
  File "/usr/lib/python3.8/site-packages/fastapi/applications.py", line 140, in __call__
    await super().__call__(scope, receive, send)
  File "/usr/lib/python3.8/site-packages/starlette/applications.py", line 134, in __call__
    await self.error_middleware(scope, receive, send)
  File "/usr/lib/python3.8/site-packages/starlette/middleware/errors.py", line 178, in __call__
    raise exc from None
  File "/usr/lib/python3.8/site-packages/starlette/middleware/errors.py", line 156, in __call__
    await self.app(scope, receive, _send)
  File "/usr/lib/python3.8/site-packages/starlette/exceptions.py", line 73, in __call__
    raise exc from None
  File "/usr/lib/python3.8/site-packages/starlette/exceptions.py", line 62, in __call__
    await self.app(scope, receive, sender)
  File "/usr/lib/python3.8/site-packages/starlette/routing.py", line 590, in __call__
    await route(scope, receive, send)
  File "/usr/lib/python3.8/site-packages/starlette/routing.py", line 208, in __call__
    await self.app(scope, receive, send)
  File "/usr/lib/python3.8/site-packages/starlette/routing.py", line 41, in app
    response = await func(request)
  File "/usr/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 715, in create
    res = await user.create(udm)
  File "/kelvin/ucs-school-import/modules/ucsschool/importer/models/import_user.py", line 324, in create
    res = await super(ImportUser, self).create(lo, validate)
  File "/kelvin/ucs-school-lib/modules/ucsschool/lib/models/base.py", line 418, in create
    await self.call_hooks(lo, 'pre', 'create')
  File "/kelvin/ucs-school-import/modules/ucsschool/importer/models/import_user.py", line 223, in call_hooks
    await func(self)
  File "/var/lib/ucs-school-import/kelvin-hooks/99univention-patch-users.py", line 45, in pre_create
    if user.school in ucr.get('univention/oxcontext/schools'):
TypeError: argument of type 'NoneType' is not iterable

Important is the penultimate line:
if user.school in ucr.get(‘univention/oxcontext/schools’):

Solution

Get the Value of the UCR on the master:

root@ucs-master:~# ucr get univention/oxcontext/schools
DEMOSCHOOL DEMOSCHOOL2

Open a shell in the kelvin-api docker container and set the UCR in there:

root@ucs-master:~# univention-app shell ucsschool-kelvin-rest-api
/kelvin # ucr set univention/oxcontext/schools='DEMOSCHOOL DEMOSCHOOL2'
Create univention/oxcontext/schools
E: your request could not be fulfilled
try `univention-config-registry --help` for more information
/kelvin # ucr get univention/oxcontext/schools
DEMOSCHOOL DEMOSCHOOL2
/kelvin # exit

Verify that the UCR is set and ignore the error message.

Root Cause

Kelvin API runs in a docker. So if you customized your import you probably use UCR variables that are actual not syncronized to the docker (Check Bug 52934)
These variables need to be set manually.

Mastodon