Skip to content

Commit

Permalink
Merge pull request #2912 from OpenNeuroOrg/worker-guard-missing-datasets
Browse files Browse the repository at this point in the history
fix(worker): Return 404 for missing datasets on draft or snapshot API calls
  • Loading branch information
nellh authored Sep 25, 2023
2 parents 4edbb03 + 4d39eff commit e753e99
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
7 changes: 4 additions & 3 deletions services/datalad/datalad_service/handlers/draft.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

import falcon
import pygit2

Expand All @@ -13,9 +15,8 @@ def on_get(self, req, resp, dataset):
"""
Return draft state (other than files).
"""
if dataset:
# Maybe turn this into status?
dataset_path = self.store.get_dataset_path(dataset)
dataset_path = self.store.get_dataset_path(dataset)
if dataset and os.path.exists(dataset_path):
repo = pygit2.Repository(dataset_path)
commit = repo.revparse_single('HEAD')
resp.media = {'hexsha': commit.hex,
Expand Down
5 changes: 4 additions & 1 deletion services/datalad/datalad_service/handlers/snapshots.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import logging

import gevent
Expand All @@ -19,7 +20,9 @@ def __init__(self, store):

def on_get(self, req, resp, dataset, snapshot=None):
"""Get the tree of files for a snapshot."""
if snapshot:
if not os.path.exists(self.store.get_dataset_path(dataset)):
resp.status = falcon.HTTP_NOT_FOUND
elif snapshot:
files = get_tree(self.store, dataset, snapshot)
response = get_snapshot(self.store, dataset, snapshot)
response['files'] = files
Expand Down
2 changes: 1 addition & 1 deletion services/datalad/datalad_service/tasks/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


LEGACY_VALIDATOR_VERSION = json.load(
open('/srv/package.json'))['dependencies']['bids-validator']
open('package.json'))['dependencies']['bids-validator']
DENO_VALIDATOR_VERSION = 'v1.13.0'

LEGACY_METADATA = {
Expand Down

0 comments on commit e753e99

Please sign in to comment.