Skip to content

Commit

Permalink
Merge pull request #1136 from dandi/asset-info-endpoint
Browse files Browse the repository at this point in the history
Simplify implementations of `get_asset()` methods
  • Loading branch information
yarikoptic authored Oct 13, 2022
2 parents ef9d853 + b1b746c commit 4f50102
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions dandi/dandiapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,11 +594,11 @@ def get_asset(self, asset_id: str) -> "BaseRemoteAsset":
method must be used instead.
"""
try:
return BaseRemoteAsset.from_base_data(
self, self.get(f"/assets/{asset_id}/info/")
)
info = self.get(f"/assets/{asset_id}/info/")
except HTTP404Error:
raise NotFoundError(f"No such asset: {asset_id!r}")
metadata = info.pop("metadata", None)
return BaseRemoteAsset.from_base_data(self, info, metadata)


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

def get_assets_with_path_prefix(
self, path: str, order: Optional[str] = None
Expand Down

0 comments on commit 4f50102

Please sign in to comment.