Skip to content

Commit b1b746c

Browse files
committed
Simplify implementations of get_asset() methods
1 parent ef9d853 commit b1b746c

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

dandi/dandiapi.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -594,11 +594,11 @@ def get_asset(self, asset_id: str) -> "BaseRemoteAsset":
594594
method must be used instead.
595595
"""
596596
try:
597-
return BaseRemoteAsset.from_base_data(
598-
self, self.get(f"/assets/{asset_id}/info/")
599-
)
597+
info = self.get(f"/assets/{asset_id}/info/")
600598
except HTTP404Error:
601599
raise NotFoundError(f"No such asset: {asset_id!r}")
600+
metadata = info.pop("metadata", None)
601+
return BaseRemoteAsset.from_base_data(self, info, metadata)
602602

603603

604604
class APIBase(BaseModel):
@@ -1039,12 +1039,11 @@ def get_asset(self, asset_id: str) -> "RemoteAsset":
10391039
ID. If the given asset does not exist, a `NotFoundError` is raised.
10401040
"""
10411041
try:
1042-
metadata = self.client.get(f"{self.version_api_path}assets/{asset_id}/")
1042+
info = self.client.get(f"{self.version_api_path}assets/{asset_id}/info/")
10431043
except HTTP404Error:
10441044
raise NotFoundError(f"No such asset: {asset_id!r} for {self}")
1045-
asset = self.get_asset_by_path(metadata["path"])
1046-
asset._metadata = metadata
1047-
return asset
1045+
metadata = info.pop("metadata", None)
1046+
return RemoteAsset.from_data(self, info, metadata)
10481047

10491048
def get_assets_with_path_prefix(
10501049
self, path: str, order: Optional[str] = None

0 commit comments

Comments
 (0)