Skip to content

Commit

Permalink
Issue #18: Use deepcopy in to_dict method to prevent values of ``…
Browse files Browse the repository at this point in the history
…udm_properties`` from being updated in objects which are copied.
  • Loading branch information
twenzel225 committed Dec 19, 2022
1 parent c3bb03f commit 8c1b2b3
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 5 deletions.
5 changes: 5 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
History
=======

2.2.1 (2022-12-15)
------------------

* Use deepcopy in ``to_dict`` method to prevent values of ``udm_properties`` from being updated in objects which are copied.

2.2.0 (2022-10-13)
--------------------

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ START_UCS_CONTAINER = docker run --detach --name "$(UCS_CONTAINER)" --hostname=m
UCS_CONTAINER_IP_CMD = . docker/common.sh && docker_container_ip $(UCS_CONTAINER)
GET_OPENAPI_SCHEMA_UDM = . docker/common.sh && get_openapi_schema "$(UCS_CONTAINER)"

KELVIN_IMG = docker.software-univention.de/ucsschool-kelvin-rest-api:1.8.0
KELVIN_IMG = docker.software-univention.de/ucsschool-kelvin-rest-api:1.8.1
KELVIN_CONTAINER = $(shell . docker/common.sh && echo "$$KELVIN_CONTAINER")
KELVIN_API_LOG_FILE = $(shell . docker/common.sh && echo "$$KELVIN_API_LOG_FILE")
KELVIN_IMG_EXISTS = . docker/common.sh && docker_img_exists "$(KELVIN_IMG)"
Expand Down
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.2.0
2.2.1
2 changes: 1 addition & 1 deletion docker/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export UDM_ONLY_TARGET_DOCKER_IMG_VERSION="${UDM_ONLY_TARGET_DOCKER_IMG}:${UCS_R
export UDM_ONLY_TARGET_DOCKER_IMG_LATEST="${UDM_ONLY_TARGET_DOCKER_IMG}:${UCS_REPOS}-latest"

export KELVIN_CONTAINER=kelvin-api
export KELVIN_REST_API_VERSION="1.8.0"
export KELVIN_REST_API_VERSION="1.8.1"
export KELVIN_REST_API_IMG="${DOCKER_REGISTRY}/ucsschool-kelvin-rest-api:${KELVIN_REST_API_VERSION}"
export KELVIN_API_LOG_FILE="/var/log/univention/ucsschool-kelvin-rest-api/http.log"

Expand Down
12 changes: 12 additions & 0 deletions tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,3 +524,15 @@ async def test_reload(
await ldap_access.modify(obj.dn, {"givenName": [(ldap3.MODIFY_REPLACE, [first_name_new])]})
await obj.reload()
assert obj.firstname == first_name_new


@pytest.mark.asyncio
async def test_as_json(kelvin_session_kwargs, new_school_user):
user = await new_school_user()
async with Session(**kelvin_session_kwargs) as session:
old_obj: User = await UserResource(session=session).get(school=user.school, name=user.name)
old_obj.udm_properties["title"] = "before"

new_user = User(**old_obj.as_dict(), session=session)
new_user.udm_properties["title"] = "after"
assert old_obj.udm_properties["title"] != new_user.udm_properties["title"]
5 changes: 3 additions & 2 deletions ucsschool/kelvin/client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# License with the Debian GNU/Linux or Univention distribution in file
# /usr/share/common-licenses/AGPL-3; if not, see
# <http://www.gnu.org/licenses/>.

import copy
import logging
from abc import ABC
from typing import Any, AsyncIterator, Dict, Iterable, List, TypeVar
Expand Down Expand Up @@ -140,7 +140,8 @@ async def delete(self) -> None:

def as_dict(self) -> Dict[str, Any]:
attrs = self._kelvin_attrs + ["dn", "url"]
return dict((attr, getattr(self, attr)) for attr in attrs)
_dict_repr = copy.deepcopy(dict((attr, getattr(self, attr)) for attr in attrs))
return _dict_repr

@classmethod
def _from_kelvin_response(cls, response: Dict[str, Any]) -> KelvinObjectType:
Expand Down

0 comments on commit 8c1b2b3

Please sign in to comment.