Skip to content

Commit 5521ba8

Browse files
committed
account for cases on cortexlab where session hasn't been created
1 parent 30607a8 commit 5521ba8

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

ibllib/oneibl/registration.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import itertools
66

77
from packaging import version
8+
from requests import HTTPError
9+
810
from one.alf.files import get_session_path, folder_parts, get_alf_path
911
from one.registration import RegistrationClient, get_dataset_type
1012
from one.remote.globus import get_local_endpoint_id, get_lab_from_endpoint_id
@@ -81,17 +83,29 @@ def register_dataset(file_list, one=None, exists=False, versions=None, **kwargs)
8183
client = IBLRegistrationClient(one)
8284

8385
# Check for protected datasets
86+
def _get_protected(pr_status):
87+
if isinstance(protected_status, list):
88+
pr = any(d['status_code'] == 403 for d in pr_status)
89+
else:
90+
pr = protected_status['status_code'] == 403
91+
92+
return pr
93+
8494
# Account for cases where we are connected to cortex lab database
8595
if one.alyx.base_url == 'https://alyx.cortexlab.net':
86-
protected_status = IBLRegistrationClient(
87-
ONE(base_url='https://alyx.internationalbrainlab.org', mode='remote')).check_protected_files(file_list)
96+
try:
97+
protected_status = IBLRegistrationClient(
98+
ONE(base_url='https://alyx.internationalbrainlab.org', mode='remote')).check_protected_files(file_list)
99+
protected = _get_protected(protected_status)
100+
except HTTPError as err:
101+
if "[Errno 500] /check-protected: 'A base session for" in str(err):
102+
# If we get an error due to the session not existing, we take this to mean no datasets are protected
103+
protected = False
104+
else:
105+
raise err
88106
else:
89107
protected_status = client.check_protected_files(file_list)
90-
91-
if isinstance(protected_status, list):
92-
protected = any(d['status_code'] == 403 for d in protected_status)
93-
else:
94-
protected = protected_status['status_code'] == 403
108+
protected = _get_protected(protected_status)
95109

96110
# If we find a protected dataset, and we don't have a force=True flag, raise an error
97111
if protected and not kwargs.pop('force', False):

0 commit comments

Comments
 (0)