|
5 | 5 | import itertools |
6 | 6 |
|
7 | 7 | from packaging import version |
| 8 | +from requests import HTTPError |
| 9 | + |
8 | 10 | from one.alf.files import get_session_path, folder_parts, get_alf_path |
9 | 11 | from one.registration import RegistrationClient, get_dataset_type |
10 | 12 | 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) |
81 | 83 | client = IBLRegistrationClient(one) |
82 | 84 |
|
83 | 85 | # 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 | + |
84 | 94 | # Account for cases where we are connected to cortex lab database |
85 | 95 | 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 |
88 | 106 | else: |
89 | 107 | 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) |
95 | 109 |
|
96 | 110 | # If we find a protected dataset, and we don't have a force=True flag, raise an error |
97 | 111 | if protected and not kwargs.pop('force', False): |
|
0 commit comments