Skip to content

Commit

Permalink
Make FileRef.get_file() raise APINotFound if container has no files
Browse files Browse the repository at this point in the history
  • Loading branch information
ambrussimon committed Mar 20, 2018
1 parent 2d3aa43 commit fd1bf5c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion api/dao/containerstorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,12 @@ def create_el(self, analysis, parent_type, parent_id, origin, uid=None):
for i, fileref_dict in enumerate(analysis.get('inputs', [])):
try:
fileref = containerutil.create_filereference_from_dictionary(fileref_dict)
analysis['inputs'][i] = fileref.get_file()
except KeyError:
# Legacy analyses already have fileinfos as inputs instead of filerefs
pass
else:
analysis['inputs'][i] = fileref.get_file()


result = super(AnalysisStorage, self).create_el(analysis)
if not result.acknowledged:
Expand Down
2 changes: 1 addition & 1 deletion api/dao/containerutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def from_dictionary(cls, d):
def get_file(self):
container = super(FileReference, self).get()

for file in container['files']:
for file in container.get('files', []):
if file['name'] == self.name:
return file

Expand Down

0 comments on commit fd1bf5c

Please sign in to comment.