diff --git a/backend/application.py b/backend/application.py index 8614dd026..74bc47a3a 100644 --- a/backend/application.py +++ b/backend/application.py @@ -100,6 +100,10 @@ def get(self): try: dataset_version = db.get_dataset_version(dataset, version) + if dataset_version is None: + self.send_error(status_code=404) + return + if dataset_version.available_from > datetime.now(): # If it's not available yet, only return if user is admin. @@ -163,6 +167,9 @@ def get(self, dataset, version=None): future_version = False version = db.get_dataset_version(dataset, version) + if version is None: + self.send_error(status_code=404) + return if version.available_from > datetime.now(): future_version = True @@ -216,6 +223,10 @@ class GenerateTemporaryLink(handlers.AuthorizedHandler): def post(self, dataset, version=None): user = self.current_user dataset_version = db.get_dataset_version(dataset, version) + if dataset_version is None: + self.send_error(status_code=404) + return + lh = db.Linkhash.create( user = user, dataset_version = dataset_version, @@ -240,6 +251,10 @@ def post(self, dataset, version=None): class DatasetFiles(handlers.AuthorizedHandler): def get(self, dataset, version=None): dataset_version = db.get_dataset_version(dataset, version) + if dataset_version is None: + self.send_error(status_code=404) + return + ret = [] for f in dataset_version.files: d = db.build_dict_from_row(f) diff --git a/backend/db.py b/backend/db.py index 884f72d48..d52c8a73d 100644 --- a/backend/db.py +++ b/backend/db.py @@ -295,16 +295,26 @@ def get_dataset(dataset): def get_dataset_version(dataset, version=None): if version: - dataset_version = (DatasetVersion - .select(DatasetVersion, Dataset) - .join(Dataset) - .where(DatasetVersion.version == version, - Dataset.short_name == dataset)).get() + try: + dataset_version = (DatasetVersion + .select(DatasetVersion, Dataset) + .join(Dataset) + .where(DatasetVersion.version == version, + Dataset.short_name == dataset)).get() + except DatasetVersion.DoesNotExist: + logging.error("get_dataset_version({}, {}): ".format(dataset, version) + + "cannot retrieve dataset version") + return else: - dataset_version = (DatasetVersionCurrent - .select(DatasetVersionCurrent, Dataset) - .join(Dataset) - .where(Dataset.short_name == dataset)).get() + try: + dataset_version = (DatasetVersionCurrent + .select(DatasetVersionCurrent, Dataset) + .join(Dataset) + .where(Dataset.short_name == dataset)).get() + except DatasetVersionCurrent.DoesNotExist: + logging.error("get_dataset_version({}, version=None): ".format(dataset) + + "cannot retrieve dataset version") + return return dataset_version