Skip to content
Snippets Groups Projects
Unverified Commit bab0207f authored by Megan Henning's avatar Megan Henning Committed by GitHub
Browse files

Merge pull request #1056 from scitran/fix-batch-no-input

Fix analysis insertion bug when batch processing multiple targets for SDK gears
parents c7e282c1 a260b1c6
No related branches found
No related tags found
No related merge requests found
......@@ -147,10 +147,10 @@ def run(batch_job):
tags.append('batch')
if gear.get('category') == 'analysis':
analysis = proposal.get('analysis', {})
if not analysis.get('label'):
analysis_base = proposal.get('analysis', {})
if not analysis_base.get('label'):
time_now = datetime.datetime.utcnow()
analysis['label'] = {'label': '{} {}'.format(gear_name, time_now)}
analysis_base['label'] = {'label': '{} {}'.format(gear_name, time_now)}
an_storage = AnalysisStorage()
acq_storage = AcquisitionStorage()
......@@ -172,6 +172,8 @@ def run(batch_job):
if gear.get('category') == 'analysis':
analysis = copy.deepcopy(analysis_base)
# Create analysis
acquisition_id = inputs.values()[0].get('id')
session_id = acq_storage.get_container(acquisition_id, projection={'session':1}).get('session')
......@@ -195,6 +197,8 @@ def run(batch_job):
if gear.get('category') == 'analysis':
analysis = copy.deepcopy(analysis_base)
# Create analysis
result = an_storage.create_job_and_analysis('sessions', bson.ObjectId(dest['id']), analysis, job_map, origin, None)
job = result.get('job')
......
......@@ -251,7 +251,9 @@ def test_batch(data_builder, as_user, as_admin, as_root):
def test_no_input_batch(data_builder, default_payload, randstr, as_admin, as_root, api_db):
project = data_builder.create_project()
session = data_builder.create_session(project=project)
session2 = data_builder.create_session(project=project)
acquisition = data_builder.create_acquisition(session=session)
acquisition2 = data_builder.create_acquisition(session=session2)
gear_name = randstr()
gear_doc = default_payload['gear']
......@@ -269,26 +271,28 @@ def test_no_input_batch(data_builder, default_payload, randstr, as_admin, as_roo
gear = r.json()['_id']
# create a batch w/o inputs targeting session
# create a batch w/o inputs targeting sessions
r = as_admin.post('/batch', json={
'gear_id': gear,
'targets': [{'type': 'session', 'id': session}]
'targets': [{'type': 'session', 'id': session}, {'type': 'session', 'id': session2}]
})
assert r.ok
batch1 = r.json()
assert len(batch1['matched']) == 1
assert len(batch1['matched']) == 2
assert batch1['matched'][0]['id'] == session
assert batch1['matched'][1]['id'] == session2
# create a batch w/o inputs targeting acquisition
# create a batch w/o inputs targeting acquisitions
r = as_admin.post('/batch', json={
'gear_id': gear,
'targets': [{'type': 'acquisition', 'id': acquisition}]
'targets': [{'type': 'acquisition', 'id': acquisition}, {'type': 'acquisition', 'id': acquisition2}]
})
assert r.ok
batch2 = r.json()
assert len(batch2['matched']) == 1
assert len(batch2['matched']) == 2
assert batch2['matched'][0]['id'] == session
assert batch1['matched'][1]['id'] == session2
# create a batch w/o inputs targeting project
r = as_admin.post('/batch', json={
......@@ -297,8 +301,9 @@ def test_no_input_batch(data_builder, default_payload, randstr, as_admin, as_roo
})
assert r.ok
batch3 = r.json()
assert len(batch3['matched']) == 1
assert len(batch3['matched']) == 2
assert batch3['matched'][0]['id'] == session
assert batch1['matched'][1]['id'] == session2
batch_id = batch1['_id']
......@@ -342,13 +347,14 @@ def test_no_input_batch(data_builder, default_payload, randstr, as_admin, as_roo
# create a batch w/o inputs targeting session
r = as_admin.post('/batch', json={
'gear_id': gear2,
'targets': [{'type': 'session', 'id': session}]
'targets': [{'type': 'session', 'id': session}, {'type': 'session', 'id': session2}]
})
assert r.ok
batch4 = r.json()
assert len(batch4['matched']) == 1
assert len(batch4['matched']) == 2
assert batch4['matched'][0]['id'] == session
assert batch1['matched'][1]['id'] == session2
batch_id = batch4['_id']
# run batch
......@@ -377,3 +383,5 @@ def test_no_input_batch(data_builder, default_payload, randstr, as_admin, as_roo
# must remove jobs manually because gears were added manually
api_db.jobs.remove({'gear_id': {'$in': [gear, gear2]}})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment