Skip to content

Commit 9195d02

Browse files
committed
When creating or updating a resource that doesn't have an id, if you supply a parameter dataset, then the resource will be assigned to that dataset and it will be compared to resources in that dataset. If a match is found, then the resource will be given the corresponding id and that resource on HDX will be overwritten.
1 parent 8cc5f0f commit 9195d02

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

‎src/hdx/data/resource.py‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -478,20 +478,20 @@ def _get_resource_id(self, **kwargs: Any) -> Optional[str]:
478478
if dataset:
479479
dataset_id = dataset.get("id")
480480
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(
481+
existing_dataset_id = self.data.get("package_id")
482+
if not existing_dataset_id or existing_dataset_id == dataset_id:
483+
self.data["package_id"] = dataset["id"]
484+
dataset_resources = dataset.get_resources()
485+
matching_index = hdx.data.resource_matcher.ResourceMatcher.match_resource_list(
485486
dataset_resources, self
486487
)
487-
)
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
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
495495
return loadedid
496496

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

0 commit comments

Comments
 (0)