From 3109220325300a71abd8034dfa8857b35ca6d06e Mon Sep 17 00:00:00 2001 From: Thomas Chopitea Date: Mon, 2 Sep 2024 17:17:01 +0000 Subject: [PATCH 1/2] Bugfix when deleting DFIQ objects --- core/web/apiv2/dfiq.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/web/apiv2/dfiq.py b/core/web/apiv2/dfiq.py index 3b27d9696..9551ad811 100644 --- a/core/web/apiv2/dfiq.py +++ b/core/web/apiv2/dfiq.py @@ -278,7 +278,8 @@ async def delete(dfiq_id: str) -> None: all_children, _ = dfiq.DFIQBase.filter(query_args={"parent_ids": db_dfiq.uuid}) if db_dfiq.dfiq_id: children, _ = dfiq.DFIQBase.filter(query_args={"parent_ids": db_dfiq.dfiq_id}) - all_children.extend(children) + if children: + all_children.extend(children) for child in all_children: if db_dfiq.dfiq_id in child.parent_ids: child.parent_ids.remove(db_dfiq.dfiq_id) From c43434c28c49d89c77a9212aef72cfc55dfc431a Mon Sep 17 00:00:00 2001 From: Thomas Chopitea Date: Tue, 3 Sep 2024 11:30:07 +0000 Subject: [PATCH 2/2] Export DFIQ objects using UUIDs --- core/web/apiv2/dfiq.py | 12 ++++++------ tests/apiv2/dfiq.py | 18 ++++++++++-------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/core/web/apiv2/dfiq.py b/core/web/apiv2/dfiq.py index 9551ad811..40bca95f5 100644 --- a/core/web/apiv2/dfiq.py +++ b/core/web/apiv2/dfiq.py @@ -189,24 +189,24 @@ async def to_archive(request: DFIQSearchRequest) -> FileResponse: os.makedirs(f"{tempdir.name}/{dir_name}") for obj in public_objs: - with open(f"{tempdir.name}/public/{obj.dfiq_id}.yaml", "w") as f: + with open(f"{tempdir.name}/public/{obj.uuid}.yaml", "w") as f: f.write(obj.to_yaml()) for obj in internal_objs: - with open(f"{tempdir.name}/internal/{obj.dfiq_id}.yaml", "w") as f: + with open(f"{tempdir.name}/internal/{obj.uuid}.yaml", "w") as f: f.write(obj.to_yaml()) with tempfile.NamedTemporaryFile(delete=False) as archive: with ZipFile(archive, "w") as zipf: for obj in public_objs: zipf.write( - f"{tempdir.name}/public/{obj.dfiq_id}.yaml", - f"public/{_TYPE_TO_DUMP_DIR[obj.type]}/{obj.dfiq_id}.yaml", + f"{tempdir.name}/public/{obj.uuid}.yaml", + f"public/{_TYPE_TO_DUMP_DIR[obj.type]}/{obj.uuid}.yaml", ) for obj in internal_objs: zipf.write( - f"{tempdir.name}/internal/{obj.dfiq_id}.yaml", - f"internal/{_TYPE_TO_DUMP_DIR[obj.type]}/{obj.dfiq_id}.yaml", + f"{tempdir.name}/internal/{obj.uuid}.yaml", + f"internal/{_TYPE_TO_DUMP_DIR[obj.type]}/{obj.uuid}.yaml", ) return FileResponse(archive.name, media_type="application/zip", filename="dfiq.zip") diff --git a/tests/apiv2/dfiq.py b/tests/apiv2/dfiq.py index 500995860..6f501f424 100644 --- a/tests/apiv2/dfiq.py +++ b/tests/apiv2/dfiq.py @@ -481,23 +481,25 @@ def test_to_archive(self): with ZipFile(io.BytesIO(response.content)) as archive: files = archive.namelist() self.assertEqual(len(files), 4) - self.assertIn("public/scenarios/S1003.yaml", files) - self.assertIn("internal/scenarios/S0003.yaml", files) - self.assertIn("public/questions/Q1020.yaml", files) - self.assertIn("internal/questions/Q1020.yaml", files) + self.assertIn("public/scenarios/test_scenario_uuid.yaml", files) + self.assertIn("internal/scenarios/test_private_scenario_uuid.yaml", files) + self.assertIn("public/questions/test_question_uuid.yaml", files) + self.assertIn("internal/questions/test_question_uuid.yaml", files) - with archive.open("public/scenarios/S1003.yaml") as f: + with archive.open("public/scenarios/test_scenario_uuid.yaml") as f: content = f.read().decode("utf-8") self.assertIn("public_scenario", content) - with archive.open("internal/scenarios/S0003.yaml") as f: + with archive.open( + "internal/scenarios/test_private_scenario_uuid.yaml" + ) as f: content = f.read().decode("utf-8") self.assertIn("private_scenario", content) - with archive.open("public/questions/Q1020.yaml") as f: + with archive.open("public/questions/test_question_uuid.yaml") as f: content = f.read().decode("utf-8") self.assertIn("semi_private_question", content) self.assertIn("public_approach", content) self.assertNotIn("internal_approach", content) - with archive.open("internal/questions/Q1020.yaml") as f: + with archive.open("internal/questions/test_question_uuid.yaml") as f: content = f.read().decode("utf-8") self.assertIn("semi_private_question", content) self.assertIn("public_approach", content)