diff --git a/api/download.py b/api/download.py index 26e947c46869bf509f8026f76a73827432e71ccc..99a4a3d5158a556f4fed02b04837463740184f04 100644 --- a/api/download.py +++ b/api/download.py @@ -139,10 +139,12 @@ class Download(base.RequestHandler): subject_prefixes = {} for session in session_dict.itervalues(): if session.get('subject'): - code = session['subject'].get('code', 'unknown_subject') - # This is bad and we should try to combine these somehow, - # or at least make sure we get all the files - subject_dict[code] = session['subject'] + subject = session.get('subject', {'code': 'unknown_subject'}) + code = subject.get('code') + if code is None: + code = 'unknown_subject' + subject['code'] = code + subject_dict[code] = subject for code, subject in subject_dict.iteritems(): subject_prefix = prefix + '/' + self._path_from_container(subject, used_subpaths, ids_of_paths, code) diff --git a/test/integration_tests/python/test_download.py b/test/integration_tests/python/test_download.py index 3a722cfb2f532483f677c49d87ef4e830031c75b..94452c918ec9f6699b0e9f807c8d3341675391d7 100644 --- a/test/integration_tests/python/test_download.py +++ b/test/integration_tests/python/test_download.py @@ -37,14 +37,10 @@ def test_download(data_builder, file_form, as_admin, api_db): r = as_admin.post('/download', json={ 'optional': False, 'filters': [{'tags': { - '-': ['minus'], - '+': ['plus'] + '-': ['minus'] }}], 'nodes': [ - {'level': 'project', '_id': project}, - {'level': 'session', '_id': session}, - {'level': 'acquisition', '_id': acquisition}, - {'level': 'acquisition', '_id':acquisition2}, + {'level': 'project', '_id': project}, ] }) assert r.ok