Move one more flush out of dicovering outputs

This commit is contained in:
mvdbeek
2020-10-26 12:01:59 +01:00
parent 0334b2f39b
commit a8191d4b8a
4 changed files with 12 additions and 3 deletions
+5
View File
@@ -2307,6 +2307,11 @@ class StorableObject:
else:
self.uuid = UUID(str(uuid))
def flush(self):
sa_session = object_session(self)
if sa_session:
sa_session.flush()
class Dataset(StorableObject, RepresentById):
states = Bunch(NEW='new',
-1
View File
@@ -283,7 +283,6 @@ class ModelPersistenceContext(metaclass=abc.ABCMeta):
association_name = f'__new_primary_file_{name}|{element_identifier_str}__'
self.add_output_dataset_association(association_name, dataset)
self.flush()
self.update_object_store_with_datasets(datasets=element_datasets['datasets'], paths=element_datasets['paths'], extra_files=element_datasets['extra_files'])
add_datasets_timer = ExecutionTimer()
self.add_datasets_to_history(element_datasets['datasets'])
+5 -1
View File
@@ -256,7 +256,11 @@ class BaseObjectStore(ObjectStore):
def _get_object_id(self, obj):
if hasattr(obj, self.store_by):
return getattr(obj, self.store_by)
obj_id = getattr(obj, self.store_by)
if obj_id is None:
obj.flush()
return obj.id
return obj_id
else:
# job's don't have uuids, so always use ID in this case when creating
# job working directories.
+2 -1
View File
@@ -81,6 +81,7 @@ def test_job_context_discover_outputs_flushes_once(mocker):
final_job_state=job_context.final_job_state,
)
collection_builder.populate()
assert spy.call_count == 1
assert spy.call_count == 0
sa_session.flush()
assert len(collection.dataset_instances) == 10
assert collection.dataset_instances[0].dataset.file_size == 1