Skip to content

Commit be7a5b6

Browse files
committed
Handle package id if given a dataset
1 parent a73c0ea commit be7a5b6

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

src/hdx/data/resource.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -476,19 +476,22 @@ def _get_resource_id(self, **kwargs: Any) -> Optional[str]:
476476
if loadedid is None:
477477
dataset = kwargs.get("dataset")
478478
if dataset:
479-
dataset_resources = dataset.get_resources()
480-
matching_index = (
481-
hdx.data.resource_matcher.ResourceMatcher.match_resource_list(
482-
dataset_resources, self
479+
dataset_id = dataset.get("id")
480+
if dataset_id:
481+
self.data["package_id"] = dataset["id"]
482+
dataset_resources = dataset.get_resources()
483+
matching_index = (
484+
hdx.data.resource_matcher.ResourceMatcher.match_resource_list(
485+
dataset_resources, self
486+
)
483487
)
484-
)
485-
if matching_index:
486-
matching_resource = dataset_resources[matching_index]
487-
loadedid = matching_resource.get("id")
488-
if loadedid:
489-
self.data["id"] = loadedid
490-
else:
491-
loadedid = None
488+
if matching_index:
489+
matching_resource = dataset_resources[matching_index]
490+
loadedid = matching_resource.get("id")
491+
if loadedid:
492+
self.data["id"] = loadedid
493+
else:
494+
loadedid = None
492495
return loadedid
493496

494497
def update_in_hdx(self, **kwargs: Any) -> int:

0 commit comments

Comments
 (0)