1515 CurationTask ,
1616 Grid ,
1717 JSONSchema ,
18+ Project ,
1819 RecordBasedMetadataTaskProperties ,
1920 RecordSet ,
2021)
22+ from synapseclient .operations import get
2123
2224
2325def extract_property_titles (schema_data : Dict [str , Any ]) -> List [str ]:
@@ -99,7 +101,6 @@ def extract_schema_properties_from_web(
99101
100102
101103def create_record_based_metadata_task (
102- project_id : str ,
103104 folder_id : str ,
104105 record_set_name : str ,
105106 record_set_description : str ,
@@ -112,6 +113,7 @@ def create_record_based_metadata_task(
112113 assignee_principal_id : Optional [Union [str , int ]] = None ,
113114 * ,
114115 synapse_client : Optional [Synapse ] = None ,
116+ project_id : Optional [str ] = None , # Deprecated, will be removed in v5.0.0
115117) -> Tuple [RecordSet , CurationTask , Grid ]:
116118 """
117119 Generate and upload CSV templates as a RecordSet for record-based metadata,
@@ -142,7 +144,6 @@ def create_record_based_metadata_task(
142144
143145 record_set, task, grid = create_record_based_metadata_task(
144146 synapse_client=syn,
145- project_id="syn12345678",
146147 folder_id="syn87654321",
147148 record_set_name="BiospecimenMetadata_RecordSet",
148149 record_set_description="RecordSet for biospecimen metadata curation",
@@ -155,9 +156,10 @@ def create_record_based_metadata_task(
155156 ```
156157
157158 Arguments:
158- project_id: The Synapse ID of the project where the folder exists.
159159 folder_id: The Synapse ID of the folder to upload RecordSet to.
160- record_set_name: Name for the RecordSet.
160+ record_set_name: Name for the RecordSet entity that will be created.
161+ A RecordSet entity captures record-based metadata as a special type of CSV and stores contributor
162+ provided metadata collected via Curator enabling sharing and download of validated metadata in Synapse.
161163 record_set_description: Description for the RecordSet.
162164 curation_task_name: Name for the CurationTask (used as data_type field).
163165 Must be unique within the project, otherwise if it matches an existing
@@ -177,6 +179,7 @@ def create_record_based_metadata_task(
177179 synapse_client: If not passed in and caching was not disabled by
178180 `Synapse.allow_client_caching(False)` this will use the last created
179181 instance from the Synapse class constructor.
182+ project_id: Deprecated, will be removed in v5.0.0
180183
181184 Returns:
182185 Tuple containing the created RecordSet, CurationTask, and Grid objects
@@ -186,8 +189,6 @@ def create_record_based_metadata_task(
186189 SynapseError: If there are issues with Synapse operations.
187190 """
188191 # Validate required parameters
189- if not project_id :
190- raise ValueError ("project_id is required" )
191192 if not folder_id :
192193 raise ValueError ("folder_id is required" )
193194 if not record_set_name :
@@ -203,8 +204,18 @@ def create_record_based_metadata_task(
203204 if not schema_uri :
204205 raise ValueError ("schema_uri is required" )
205206
207+ if project_id :
208+ synapse_client .logger .warning (
209+ "The 'project_id' parameter is deprecated and will be removed in v5.0.0. "
210+ "The project ID will be inferred from the folder ID provided."
211+ )
212+
206213 synapse_client = Synapse .get_client (synapse_client = synapse_client )
207214
215+ project_id = project_id_from_entity_id (
216+ entity_id = folder_id , synapse_client = synapse_client
217+ )
218+
208219 template_df = extract_schema_properties_from_web (
209220 syn = synapse_client , schema_uri = schema_uri
210221 )
@@ -283,3 +294,23 @@ def create_record_based_metadata_task(
283294 raise e
284295
285296 return record_set_with_data , curation_task , curation_grid
297+
298+
299+ def project_id_from_entity_id (entity_id : str , synapse_client : Synapse ) -> str :
300+ """
301+ Helper function to retrieve the project ID from a given entity ID by traversing up the hierarchy.
302+
303+ Args:
304+ entity_id: The Synapse ID of the entity (e.g., folder, file) to start from.
305+ synapse_client: Authenticated Synapse client instance
306+ """
307+
308+ # Get the project ID from the folder ID
309+ current_obj = get (entity_id , synapse_client = synapse_client )
310+ iter = 0
311+ while not isinstance (current_obj , Project ):
312+ current_obj = get (current_obj .parent_id , synapse_client = synapse_client )
313+ iter += 1
314+ if iter > 1000 :
315+ raise ValueError ("Could not find project ID in folder hierarchy" )
316+ return current_obj .id
0 commit comments