From 55032b0fa36db0fc4ee8ce772a15c831397bb821 Mon Sep 17 00:00:00 2001 From: luisa-beerboom <101706784+luisa-beerboom@users.noreply.github.com> Date: Mon, 18 Mar 2024 15:12:46 +0100 Subject: [PATCH] Fix participant import re-upload structure_level error (#2313) --- .../action/actions/user/participant_import.py | 1 + .../action/user/test_participant_import.py | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/openslides_backend/action/actions/user/participant_import.py b/openslides_backend/action/actions/user/participant_import.py index cb51c59f7..c20029c02 100644 --- a/openslides_backend/action/actions/user/participant_import.py +++ b/openslides_backend/action/actions/user/participant_import.py @@ -31,6 +31,7 @@ def update_instance(self, instance: dict[str, Any]) -> dict[str, Any]: return instance def update_models_to_create(self, model_name: str, field_name: str) -> None: + self.models_to_create[field_name] = [] to_create: set[str] = { entry["value"] for row in self.rows diff --git a/tests/system/action/user/test_participant_import.py b/tests/system/action/user/test_participant_import.py index 921eeb44e..f468d68ec 100644 --- a/tests/system/action/user/test_participant_import.py +++ b/tests/system/action/user/test_participant_import.py @@ -1051,3 +1051,44 @@ def test_json_upload_legacy_username(self) -> None: self.json_upload_legacy_username() response = self.request("participant.import", {"id": 1, "import": True}) self.assert_status_code(response, 200) + + def test_reupload_with_structure_level(self) -> None: + import_data = { + "username": "test", + "default_password": "secret", + "is_active": "1", + "is_physical_person": "F", + "number": "strange number", + "structure_level": ["testlevel", "notfound"], + "vote_weight": "1.12", + "comment": "my comment", + "is_present": "0", + "groups": ["testgroup", "notfound_group1", "notfound_group2"], + "wrong": 15, + } + response = self.request( + "participant.json_upload", + { + "meeting_id": 1, + "data": [import_data.copy()], + }, + ) + self.assert_status_code(response, 200) + response = self.request( + "participant.import", + {"id": response.json["results"][0][0].get("id"), "import": True}, + ) + self.assert_status_code(response, 200) + response = self.request( + "participant.json_upload", + { + "meeting_id": 1, + "data": [import_data], + }, + ) + self.assert_status_code(response, 200) + response = self.request( + "participant.import", + {"id": response.json["results"][0][0].get("id"), "import": True}, + ) + self.assert_status_code(response, 200)