Skip to content

Commit

Permalink
Catch KeyError, extend test and change flag name
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielle6249 committed Jul 16, 2024
1 parent 35c894a commit 5ae4647
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
8 changes: 3 additions & 5 deletions girder/girder_large_image/rest/large_image_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ def _deleteCachedImages(self, spec, associatedImages=False, imageKey=None):
'existing or unfinished large images.')
.modelParam('id', 'The ID of the folder.', model=Folder, level=AccessType.WRITE,
required=True)
.param('createJobs', 'Whether job(s) should be created for each large image.',
.param('force', 'Whether creation job(s) should be forced for each large image.',
required=False, default=False, dataType='boolean')
.param('localJobs', 'Whether the job(s) created should be local.', required=False,
default=False, dataType='boolean')
Expand All @@ -465,9 +465,7 @@ def _deleteCachedImages(self, spec, associatedImages=False, imageKey=None):
)
def createLargeImages(self, folder, params):
user = self.getCurrentUser()
createJobs = params.get('createJobs')
if createJobs:
createJobs = 'always' or True
createJobs = 'always' if self.boolParam('force', params, default=False) else True
return self.createImagesRecurseOption(folder=folder, createJobs=createJobs, user=user,
recurse=params.get('recurse'),
localJobs=params.get('localJobs'))
Expand Down Expand Up @@ -496,7 +494,7 @@ def createImagesRecurseOption(self, folder, createJobs, user, recurse, localJobs
ImageItem().getMetadata(item)
result['itemsSkipped'] += 1
continue
except TileSourceError:
except (TileSourceError, KeyError):
previousFileId = item['largeImage'].get('originalId',
item['largeImage']['fileId'])
ImageItem().delete(item)
Expand Down
12 changes: 12 additions & 0 deletions girder/test_girder/test_large_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,18 @@ def testFolderCreateImages(server, admin, user, fsAssetstore):
item = Item().load(itemId, user=admin)
# Check that this item became a large image again
assert 'largeImage' in item
# Hitting the endpoint again should skip the item
resp = server.request(
method='PUT', path=f'/large_image/folder/{folderId}/tiles', user=admin)
assert utilities.respStatus(resp) == 200
assert resp.json['itemsSkipped'] == 1
# If the item's source isn't working, it should be recreated.
item['largeImage']['sourceName'] = 'unknown'
Item().updateItem(item)
resp = server.request(
method='PUT', path=f'/large_image/folder/{folderId}/tiles', user=admin)
assert utilities.respStatus(resp) == 200
assert resp.json['largeImagesRemovedAndRecreated'] == 1


@pytest.mark.singular()
Expand Down

0 comments on commit 5ae4647

Please sign in to comment.