From d63290c36ce44bc86525bebf4fead804676ddefa Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 28 Oct 2026 01:00:46 +0000 Subject: [PATCH] Remove two server-compatibility kludges which are no longer needed - get_instance(): drop the check meant to tell that the 'dandi-staging' instance identifier was removed (in 0.74.0, in favor of 'dandi-sandbox'). It never ran for an identifier given as a string, since looking it up in known_instances raised KeyError first, and the rename is more than a year old. - Downloads: stop retrying on HTTP 400. It was added in 2020 for Girder (gh-87), whose support has since been removed; each retry requests the same archive download URL again, which would not turn a 400 into a success. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_014sJtxzEPbSxycxetp4DquU --- dandi/download.py | 6 +----- dandi/tests/test_download.py | 24 +++++++++++++++++++++--- dandi/utils.py | 5 ----- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/dandi/download.py b/dandi/download.py index a87d5380e..2b8faf748 100644 --- a/dandi/download.py +++ b/dandi/download.py @@ -1213,11 +1213,7 @@ def _check_attempts_and_sleep( lgr.debug("%s - download failed after %d attempts: %s", path, attempt, exc) return 0 if exc.response is not None: - if exc.response.status_code not in ( - 400, # Bad Request, but happened with girder: - # https://github.com/dandi/dandi-cli/issues/87 - *RETRY_STATUSES, - ): + if exc.response.status_code not in RETRY_STATUSES: lgr.debug( "%s - download failed due to response %d: %s", path, diff --git a/dandi/tests/test_download.py b/dandi/tests/test_download.py index 43bb9579f..cd659ada0 100644 --- a/dandi/tests/test_download.py +++ b/dandi/tests/test_download.py @@ -1462,6 +1462,24 @@ def test__check_attempts_and_sleep() -> None: assert mock_sleep.call_args.args[0] >= 0 +@pytest.mark.ai_generated +@pytest.mark.parametrize("status_code", [400, 403, 404]) +def test__check_attempts_and_sleep_no_retry(status_code: int) -> None: + response = requests.Response() + response.status_code = status_code + with mock.patch("time.sleep") as mock_sleep: + assert ( + _check_attempts_and_sleep( + Path("some/path"), + HTTPError(response=response), + attempt=1, + attempts_allowed=2, + ) + == 0 + ) + mock_sleep.assert_not_called() + + @pytest.mark.parametrize("status_code", [429, 503]) def test__check_attempts_and_sleep_retries(status_code: int) -> None: f = partial(_check_attempts_and_sleep, Path("some/path")) @@ -1553,9 +1571,9 @@ def test_download_zarr_with_glob_filter( all_files = list_paths(zarr_dir) assert len(all_files) > 0 for f in all_files: - assert f.name.startswith(".z") or f.name == "zarr.json", ( - f"Non-metadata file downloaded: {f}" - ) + assert ( + f.name.startswith(".z") or f.name == "zarr.json" + ), f"Non-metadata file downloaded: {f}" @pytest.mark.ai_generated diff --git a/dandi/utils.py b/dandi/utils.py index cd6ea7afd..eea572911 100644 --- a/dandi/utils.py +++ b/dandi/utils.py @@ -576,11 +576,6 @@ def get_instance(dandi_instance_id: str | DandiInstance) -> DandiInstance: else: dandi_id = dandi_instance_id instance = known_instances[dandi_id] - if dandi_id == "dandi-staging": - raise ValueError( - "'dandi-staging' DANDI instance identifier was removed. " - "The instance was renamed into 'dandi-sandbox', please use that identifier instead." - ) if redirector_url is None: assert instance is not None return _get_instance(instance.api.rstrip("/"), True, instance, dandi_id)