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

Fix uploading Zarr within a BIDS dataset; typing-check guided fix for handling requests exception #1331

Merged
merged 3 commits into from
Sep 29, 2023
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
5 changes: 4 additions & 1 deletion dandi/dandiapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1450,7 +1450,10 @@
else:
break
except requests.HTTPError as e:
url = e.request.url
if e.request is not None and isinstance(e.request.url, str):
url = e.request.url

Check warning on line 1454 in dandi/dandiapi.py

View check run for this annotation

Codecov / codecov/patch

dandi/dandiapi.py#L1453-L1454

Added lines #L1453 - L1454 were not covered by tests
else:
raise # reraise since we need to figure out how to handle such a case

Check warning on line 1456 in dandi/dandiapi.py

View check run for this annotation

Codecov / codecov/patch

dandi/dandiapi.py#L1456

Added line #L1456 was not covered by tests
if strip_query:
url = urlunparse(urlparse(url)._replace(query=""))
return url
Expand Down
2 changes: 1 addition & 1 deletion dandi/files/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def get_metadata(
)


class ZarrBIDSAsset(BIDSAsset, ZarrAsset):
class ZarrBIDSAsset(ZarrAsset, BIDSAsset):
"""
.. versionadded:: 0.46.0

Expand Down
16 changes: 16 additions & 0 deletions dandi/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,22 @@ def bids_nwb_dandiset(
return new_dandiset


# TODO: refactor: avoid duplication and come up with some fixture helper which would
# just need specify bids example name
@pytest.fixture()
def bids_zarr_dandiset(
new_dandiset: SampleDandiset, bids_examples: Path
) -> SampleDandiset:
shutil.copytree(
bids_examples / "micr_SEMzarr",
new_dandiset.dspath,
dirs_exist_ok=True,
ignore=shutil.ignore_patterns(dandiset_metadata_file),
)
(new_dandiset.dspath / "CHANGES").write_text("0.1.0 2014-11-03\n")
return new_dandiset


@pytest.fixture()
def bids_dandiset_invalid(
new_dandiset: SampleDandiset, bids_error_examples: Path
Expand Down
13 changes: 13 additions & 0 deletions dandi/tests/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,19 @@ def test_upload_zarr(new_dandiset: SampleDandiset) -> None:
new_dandiset.upload()


# identical to above, but different scenaior/fixture and path. TODO: avoid duplication
def test_upload_bids_zarr(bids_zarr_dandiset: SampleDandiset) -> None:
bids_zarr_dandiset.upload()
assets = list(bids_zarr_dandiset.dandiset.get_assets())
assert len(assets) > 10 # it is a bigish dataset
(asset,) = [a for a in assets if a.path.endswith(".zarr")]
assert isinstance(asset, RemoteZarrAsset)
assert asset.asset_type is AssetType.ZARR
assert asset.path.endswith(".zarr")
# Test that uploading again without any changes works:
bids_zarr_dandiset.upload()


def test_upload_different_zarr(tmp_path: Path, zarr_dandiset: SampleDandiset) -> None:
asset = zarr_dandiset.dandiset.get_asset_by_path("sample.zarr")
assert isinstance(asset, RemoteZarrAsset)
Expand Down