diff --git a/browse.py b/browse.py index 09945d8fc..bf1ea0dee 100644 --- a/browse.py +++ b/browse.py @@ -95,11 +95,9 @@ def transform(row): offset=max(0, offset - qcoll.total_rows()), limit=limit - len(colls), output=AS_DICT) datas = map(transform, list(qdata)) - if len(colls) + len(datas) == 0: - # No results at all? - # Make sure the collection actually exists. - if not collection.exists(ctx, coll): - return api.Error('nonexistent', 'The given path does not exist') + # No results at all? Make sure the collection actually exists. + if len(colls) + len(datas) == 0 and not collection.exists(ctx, coll): + return api.Error('nonexistent', 'The given path does not exist') # (checking this beforehand would waste a query in the most common situation) return OrderedDict([('total', qcoll.total_rows() + qdata.total_rows()), @@ -177,11 +175,9 @@ def transform(row): colls = map(transform, [d for d in list(qcoll) if _filter_vault_deposit_index(d)]) - if len(colls) == 0: - # No results at all? - # Make sure the collection actually exists. - if not collection.exists(ctx, coll): - return api.Error('nonexistent', 'The given path does not exist') + # No results at all? Make sure the collection actually exists. + if len(colls) == 0 and not collection.exists(ctx, coll): + return api.Error('nonexistent', 'The given path does not exist') # (checking this beforehand would waste a query in the most common situation) return OrderedDict([('total', qcoll.total_rows()), diff --git a/datarequest.py b/datarequest.py index 9b5165d04..fd81f3252 100644 --- a/datarequest.py +++ b/datarequest.py @@ -846,11 +846,9 @@ def transform_status(row): datarequest['status'] = datarequest_status['status'] break - if len(colls) == 0: - # No results at all? - # Make sure the collection actually exists - if not collection.exists(ctx, coll): - return api.Error('nonexistent', 'The given path does not exist') + # No results at all? Make sure the collection actually exists. + if len(colls) == 0 and not collection.exists(ctx, coll): + return api.Error('nonexistent', 'The given path does not exist') # (checking this beforehand would waste a query in the most common situation) return OrderedDict([('total', qcoll.total_rows()), ('items', colls)])