Repository: fractal-analytics-platform/fractal-client (language: python)

Issue:
`fractal --batch project new` should return both {project,dataset} ID
This is needed to use in scripts, without resorting to auxiliary python scripts.
`fractal --batch project new` should return both {project,dataset} ID
This is needed to use in scripts, without resorting to auxiliary python scripts.


Discussion / hints:

Fix patch:
diff --git a/fractal/client/cmd/_project.py b/fractal/client/cmd/_project.py
index 947490539..a38425999 100644
--- a/fractal/client/cmd/_project.py
+++ b/fractal/client/cmd/_project.py
@@ -35,7 +35,14 @@ async def project_create(
     )
     project = check_response(res, expected_status_code=201, coerce=ProjectRead)
     if batch:
-        return PrintInterface(retcode=0, data=project.id)
+        if len(project.dataset_list) > 1:
+            msg = (
+                f"Created project with {len(project.dataset_list)}>1 "
+                "datasets, cannot use --batch to provide standard output."
+            )
+            raise ValueError(msg)
+        dataset_id = project.dataset_list[0].id
+        return PrintInterface(retcode=0, data=f"{project.id} {dataset_id}")
     else:
         return RichJsonInterface(retcode=0, data=project.dict())
 


Test patch:
diff --git a/tests/test_project.py b/tests/test_project.py
index e191e92d3..ed911a98a 100644
--- a/tests/test_project.py
+++ b/tests/test_project.py
@@ -16,7 +16,9 @@ async def test_project_create_batch(
     res = await invoke("--batch project new project_name project_path")
     debug(res)
     debug(res.data)
-    assert res.data == 1
+    project_id, dataset_id = map(int, res.data.split())
+    assert project_id == 1
+    assert dataset_id == 1
 
 
 async def test_project_list(clear_db, testserver, register_user, invoke):
@@ -42,8 +44,9 @@ async def test_add_dataset(clear_db, testserver, register_user, invoke):
 
     res = await invoke("--batch project new prj0 prj_path0")
     assert res.retcode == 0
+    debug(res.data)
+    project_id, dataset_id = map(int, res.data.split())
 
-    project_id = int(res.data)
     res = await invoke(f"project add-dataset {project_id} {DATASET_NAME}")
     assert res.retcode == 0
     res.show()