Skip to content

Commit cb984e8

Browse files
authored
Merge pull request #1331 from dandi/bf-1307
Fix uploading Zarr within a BIDS dataset
2 parents 697af7c + f6a9970 commit cb984e8

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

dandi/dandiapi.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1450,7 +1450,10 @@ def get_content_url(
14501450
else:
14511451
break
14521452
except requests.HTTPError as e:
1453-
url = e.request.url
1453+
if e.request is not None and isinstance(e.request.url, str):
1454+
url = e.request.url
1455+
else:
1456+
raise # reraise since we need to figure out how to handle such a case
14541457
if strip_query:
14551458
url = urlunparse(urlparse(url)._replace(query=""))
14561459
return url

dandi/files/bids.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def get_metadata(
235235
)
236236

237237

238-
class ZarrBIDSAsset(BIDSAsset, ZarrAsset):
238+
class ZarrBIDSAsset(ZarrAsset, BIDSAsset):
239239
"""
240240
.. versionadded:: 0.46.0
241241

dandi/tests/fixtures.py

+16
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,22 @@ def bids_nwb_dandiset(
628628
return new_dandiset
629629

630630

631+
# TODO: refactor: avoid duplication and come up with some fixture helper which would
632+
# just need specify bids example name
633+
@pytest.fixture()
634+
def bids_zarr_dandiset(
635+
new_dandiset: SampleDandiset, bids_examples: Path
636+
) -> SampleDandiset:
637+
shutil.copytree(
638+
bids_examples / "micr_SEMzarr",
639+
new_dandiset.dspath,
640+
dirs_exist_ok=True,
641+
ignore=shutil.ignore_patterns(dandiset_metadata_file),
642+
)
643+
(new_dandiset.dspath / "CHANGES").write_text("0.1.0 2014-11-03\n")
644+
return new_dandiset
645+
646+
631647
@pytest.fixture()
632648
def bids_dandiset_invalid(
633649
new_dandiset: SampleDandiset, bids_error_examples: Path

dandi/tests/test_upload.py

+13
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,19 @@ def test_upload_zarr(new_dandiset: SampleDandiset) -> None:
292292
new_dandiset.upload()
293293

294294

295+
# identical to above, but different scenaior/fixture and path. TODO: avoid duplication
296+
def test_upload_bids_zarr(bids_zarr_dandiset: SampleDandiset) -> None:
297+
bids_zarr_dandiset.upload()
298+
assets = list(bids_zarr_dandiset.dandiset.get_assets())
299+
assert len(assets) > 10 # it is a bigish dataset
300+
(asset,) = [a for a in assets if a.path.endswith(".zarr")]
301+
assert isinstance(asset, RemoteZarrAsset)
302+
assert asset.asset_type is AssetType.ZARR
303+
assert asset.path.endswith(".zarr")
304+
# Test that uploading again without any changes works:
305+
bids_zarr_dandiset.upload()
306+
307+
295308
def test_upload_different_zarr(tmp_path: Path, zarr_dandiset: SampleDandiset) -> None:
296309
asset = zarr_dandiset.dandiset.get_asset_by_path("sample.zarr")
297310
assert isinstance(asset, RemoteZarrAsset)

0 commit comments

Comments
 (0)