Skip to content

Commit

Permalink
remove inconsitencies in how files are added;
Browse files Browse the repository at this point in the history
Adding files is now the callers task and not handled by persistence;
  • Loading branch information
hannesrichter committed Jun 24, 2023
1 parent 6a1ddef commit 5d64972
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
4 changes: 0 additions & 4 deletions koi_api/persistence/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
7 changes: 7 additions & 0 deletions koi_api/resources/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions koi_api/resources/label_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions koi_api/resources/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions koi_api/resources/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit 5d64972

Please sign in to comment.