diff --git a/core/web/apiv2/dfiq.py b/core/web/apiv2/dfiq.py index 3b27d9696..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") @@ -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) 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)