Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes exceptions due to DoesNotExist when looking up dataset versions #502

Merged
merged 2 commits into from
Jan 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions backend/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down
29 changes: 20 additions & 9 deletions backend/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
TextField,
fn,
)
import logging
import settings

database = MySQLDatabase(
Expand Down Expand Up @@ -295,16 +296,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


Expand Down