Univention Bugzilla – Bug 54127
Handle new expiration_date field in Kelvin API
Last modified: 2022-07-04 10:11:35 CEST
+++ This bug was initially created as a clone of Bug #54116 +++ +++ This bug was initially created as a clone of Bug #54126 +++ The Kelvin REST API is getting a new user resource field "expiration_date". Add support for it in the User class. Handle older Kelvin API versions without "expiration_date" field safely.
Added support for expiration_date in version 1.5.1 of the package. [master] 9eedf16 Bug #54127: handle new expiration_date field in Kelvin API https://test.pypi.org/project/kelvin-rest-api-client/1.5.1/ https://github.com/univention/kelvin-rest-api-client/commit/9eedf167f2a50aacfd7146f8672e575256b0e7e9 https://kelvin-rest-api-client.readthedocs.io/en/latest/history.html TODO: verify handling of Kelvin API < 1.5.1 (without expiration_date field).
The Kelvin Client cannot handle older Kelvin APIs yet. Executed Code: import asyncio from ucsschool.kelvin.client import Session, User, UserResource if __name__ == "__main__": async def get_user(username: str) -> User: async with Session( "Administrator", "univention", "10.200.6.110", verify=False ) as session: return await UserResource(session=session).get(name=username) obj: User = asyncio.run(get_user("demo_teacher")) print(obj.as_dict()) print(obj.firstname, obj.lastname) Traceback: Traceback (most recent call last): File "/Users/ole/Library/Application Support/JetBrains/PyCharm2021.2/scratches/scratch.py", line 14, in <module> obj: User = asyncio.run(get_user("demo_teacher")) File "/opt/homebrew/Cellar/python@3.9/3.9.8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/runners.py", line 44, in run return loop.run_until_complete(main) File "/opt/homebrew/Cellar/python@3.9/3.9.8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete return future.result() File "/Users/ole/Library/Application Support/JetBrains/PyCharm2021.2/scratches/scratch.py", line 12, in get_user return await UserResource(session=session).get(name=username) File "/Volumes/CSData/Repos/kelvin-rest-api-client/ucsschool/kelvin/client/base.py", line 189, in get return await self.get_from_url(url) File "/Volumes/CSData/Repos/kelvin-rest-api-client/ucsschool/kelvin/client/base.py", line 201, in get_from_url obj = self.Meta.kelvin_object._from_kelvin_response(resp_json) File "/Volumes/CSData/Repos/kelvin-rest-api-client/ucsschool/kelvin/client/user.py", line 166, in _from_kelvin_response if response["expiration_date"]: KeyError: 'expiration_date'
* The client can now handle Kelvin server version <1.5.1 without 'expiration_date' field (force pushed). * It "raises" a warning, when it detects and handles a missing 'expiration_date' field. * The documentation now contains a note about the field having been added with server version 1.5.1 (see https://kelvin-rest-api-client.readthedocs.io/en/latest/usage-users.html). [master 6711fdf] Bug #54127: handle new expiration_date field in Kelvin API
OK: Warning is shown if 1.5.1 client is used against 1.5.0 API /kelvin-rest-api-client/ucsschool/kelvin/client/user.py:168: RuntimeWarning: User attribute in Kelvin REST API response missing 'expiration_date' attribute. Server version probably < '1.5.1'. OK: https://kelvin-rest-api-client.readthedocs.io/en/latest/readme.html#tests against 4.4 and 5.0 OK: manual tests against 4.4 and 5.0 OK: code review OK: changelog + version OK: docs -> verified
Published to PyPI.