From 43e175dcd215232069f9900792a8d33ee5b91912 Mon Sep 17 00:00:00 2001 From: alaskowski <alaskowski@ethz.ch> Date: Thu, 5 Oct 2023 12:45:20 +0200 Subject: [PATCH] SSDM-55: improved backwards-compatibility --- .../src/python/pybis/dataset.py | 18 +++++++++++++ .../src/python/pybis/openbis_object.py | 27 +++++++++++++++++-- .../src/python/tests/test_dataset.py | 2 ++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/api-openbis-python3-pybis/src/python/pybis/dataset.py b/api-openbis-python3-pybis/src/python/pybis/dataset.py index c8ba69d1dfe..236571ced81 100644 --- a/api-openbis-python3-pybis/src/python/pybis/dataset.py +++ b/api-openbis-python3-pybis/src/python/pybis/dataset.py @@ -892,6 +892,16 @@ class DataSet( "permId": DSpermId, "@type": "as.dto.datastore.id.DataStorePermId", } + + version = self.openbis.get_server_information().openbis_version + if version is not None: + if 'SNAPSHOT' not in version and not version.startswith( + '7') and 'UNKNOWN' not in version: + if (request['method'] in ('createDataSetTypes', 'createDataSets') + and 'metaData' in request['params'][1][0]): + del request['params'][1][0]['metaData'] + + resp = self.openbis._post_request(self.openbis.as_v3, request) if VERBOSE: @@ -908,6 +918,14 @@ class DataSet( props = self.formatter.format(self.p._all_props()) request["params"][1][0]["properties"] = props + version = self.openbis.get_server_information().openbis_version + if version is not None: + if 'SNAPSHOT' not in version and not version.startswith( + '7') and 'UNKNOWN' not in version: + if (request['method'] in ('updateDataSetTypes', 'updateDataSets') + and 'metaData' in request['params'][1][0]): + del request['params'][1][0]['metaData'] + self.openbis._post_request(self.openbis.as_v3, request) if VERBOSE: print("DataSet successfully updated.") diff --git a/api-openbis-python3-pybis/src/python/pybis/openbis_object.py b/api-openbis-python3-pybis/src/python/pybis/openbis_object.py index 195fcbe9dc9..8f12de6b0d4 100644 --- a/api-openbis-python3-pybis/src/python/pybis/openbis_object.py +++ b/api-openbis-python3-pybis/src/python/pybis/openbis_object.py @@ -233,7 +233,9 @@ class OpenBisObject: if 'SNAPSHOT' not in version and not version.startswith('7') and 'UNKNOWN' not in version: if request['method'] == 'createPropertyTypes' and 'multiValue' in request['params'][1][0]: del request['params'][1][0]['multiValue'] - if (request['method'] in ('createSampleTypes', 'createExperimentTypes', 'createDataSetTypes') + if (request['method'] in ('createSampleTypes', 'createSamples', + 'createExperimentTypes', 'createExperiments', + 'createDataSetTypes', 'createDataSets') and 'metaData' in request['params'][1][0]): del request['params'][1][0]['metaData'] @@ -255,7 +257,9 @@ class OpenBisObject: version = self.openbis.get_server_information().openbis_version if version is not None: if 'SNAPSHOT' not in version and not version.startswith('7') and 'UNKNOWN' not in version: - if (request['method'] in ('updateSampleTypes', 'updateExperimentTypes', 'updateDataSetTypes') + if (request['method'] in ('updateSampleTypes', 'updateSamples', + 'updateExperimentTypes', 'updateExperiments', + 'updateDataSetTypes', 'updateDataSets') and 'metaData' in request['params'][1][0]): del request['params'][1][0]['metaData'] @@ -327,11 +331,14 @@ class Transaction: import copy + version = None for entity_type in self.entities: for mode in self.entities[entity_type]: request_coll = [] for entity in self.entities[entity_type][mode]: + if version is None: + version = entity.openbis.get_server_information().openbis_version if mode == "delete": delete_options = get_type_for_entity(entity_type, "delete") delete_options["reason"] = self.reason @@ -374,6 +381,22 @@ class Transaction: else: raise ValueError(f"Unkown mode: {mode}") + if version is not None: + if 'SNAPSHOT' not in version and not version.startswith( + '7') and 'UNKNOWN' not in version: + if request['method'] == 'createPropertyTypes' and 'multiValue' in \ + request['params'][1][0]: + del request['params'][1][0]['multiValue'] + if (request['method'] in ('createSampleTypes', 'createSamples', + 'createExperimentTypes', 'createExperiments', + 'createDataSetTypes', 'createDataSets', + 'updateSampleTypes', 'updateSamples', + 'updateExperimentTypes', 'updateExperiments', + 'updateDataSetTypes', 'updateDataSets' + ) + and 'metaData' in request['params'][1][0]): + del request['params'][1][0]['metaData'] + request_coll.append(request) if request_coll: diff --git a/api-openbis-python3-pybis/src/python/tests/test_dataset.py b/api-openbis-python3-pybis/src/python/tests/test_dataset.py index 12fb6f69338..3417b17c948 100644 --- a/api-openbis-python3-pybis/src/python/tests/test_dataset.py +++ b/api-openbis-python3-pybis/src/python/tests/test_dataset.py @@ -143,6 +143,8 @@ def test_create_delete_dataset(space): # delete datasets dataset.delete("dataset creation test on " + timestamp, True) + # Give openbis some time to process it + time.sleep(1) # check that permanent deletion is working deletions = o.get_deletions(0, 10) assert len(deletions) == 0 -- GitLab