diff --git a/koi_api/persistence/core.py b/koi_api/persistence/core.py index 27afc65..b05b68b 100644 --- a/koi_api/persistence/core.py +++ b/koi_api/persistence/core.py @@ -13,7 +13,6 @@ # GNU Lesser General Public License is distributed along with this # software and can be found at http://www.gnu.org/licenses/lgpl.html -from koi_api.orm import db from koi_api.orm.file import ORMFile import gzip from uuid import uuid4 @@ -54,9 +53,6 @@ def store_file(self, data): f.write(data) f.close() - db.session.add(newFile) - db.session.commit() - return newFile def remove_file(self, file: ORMFile): diff --git a/koi_api/resources/instance.py b/koi_api/resources/instance.py index 4ec3b43..1f2b0ba 100644 --- a/koi_api/resources/instance.py +++ b/koi_api/resources/instance.py @@ -637,6 +637,8 @@ def post(self, model_uuid, model, instance_uuid, instance, me): data = request.data file_pers = persistence.store_file(data) + db.session.add(file_pers) + # TODO: prevent existing inferencedata to become orphaned newRequest = ORMInstanceInferenceData() newRequest.file = file_pers @@ -707,6 +709,9 @@ def post(self, model_uuid, model, instance_uuid, instance, me): data = request.data file_pers = persistence.store_file(data) + + db.session.add(file_pers) + new_uuid = uuid4() # TODO: prevent existing inferencedata to become orphaned @@ -865,6 +870,8 @@ def post(self, model_uuid, model, instance_uuid, instance, me, json_object): file_pers = persistence.store_file(value) + db.session.add(file_pers) + new_desc.descriptor_file = file_pers db.session.add(new_desc) diff --git a/koi_api/resources/label_request.py b/koi_api/resources/label_request.py index 334ccfb..1a30306 100644 --- a/koi_api/resources/label_request.py +++ b/koi_api/resources/label_request.py @@ -153,6 +153,8 @@ def post(self, model_uuid, model, instance_uuid, instance, me, request_uuid): label = request.data file_pers = persistence.store_file(label) + db.session.add(file_pers) + new_uuid = uuid4() new_data = ORMSampleLabel() diff --git a/koi_api/resources/model.py b/koi_api/resources/model.py index 993db1c..41dd1eb 100644 --- a/koi_api/resources/model.py +++ b/koi_api/resources/model.py @@ -332,6 +332,7 @@ def post(self, model_uuid, model, me): db.session.add(new_param) # TODO: prevent existing code to become orphaned + db.session.add(file_pers) newCode = ORMModelCode() newCode.file = file_pers db.session.add(newCode) @@ -379,6 +380,8 @@ def post(self, model_uuid, model, me): data = request.data file_pers = persistence.store_file(data) + db.session.add(file_pers) + # TODO: prevent existing plugin to become orphaned newVisual = ORMModelVisualPlugin() newVisual.file = file_pers @@ -425,6 +428,8 @@ def post(self, model_uuid, model, me): data = request.data file_pers = persistence.store_file(data) + db.session.add(file_pers) + # TODO: prevent existing plugin to become orphaned newRequest = ORMModelLabelRequestPlugin() newRequest.file = file_pers diff --git a/koi_api/resources/sample.py b/koi_api/resources/sample.py index 8b8d334..c1c362f 100644 --- a/koi_api/resources/sample.py +++ b/koi_api/resources/sample.py @@ -925,6 +925,8 @@ def post( data_raw = request.data file_pers = persistence.store_file(data_raw) + db.session.add(file_pers) + sample.sample_last_modified = datetime.utcnow() sample.sample_etag = token_hex(16) data.data_last_modified = datetime.utcnow() @@ -933,7 +935,6 @@ def post( instance.instance_samples_etag = token_hex(16) data.file = file_pers - db.session.add(file_pers) db.session.commit() return SUCCESS() @@ -1056,6 +1057,8 @@ def post( data_raw = request.data file_pers = persistence.store_file(data_raw) + db.session.add(file_pers) + label.file = file_pers sample.sample_last_modified = datetime.utcnow() @@ -1065,7 +1068,6 @@ def post( instance.instance_samples_last_modified = datetime.utcnow() instance.instance_samples_etag = token_hex(16) - db.session.add(file_pers) db.session.commit() return SUCCESS()