OCHA-DAP / hdx-python-api

Python API for interacting with the HDX Data Portal
http://data.humdata.org
MIT License
80 stars 16 forks source link

update to resource format fails without error #21

Closed cjhendrix closed 4 years ago

cjhendrix commented 4 years ago

Below is the code snippet that produces the behavior (targets a dataset on feature). Note that the format mapping dictionary has entries that will change "badformat" to "goodformat" and vice versa, so you don't have to manually edit the test dataset manually each time.

# isolated snippet that tests ability to identify a change and make it in ckan.
# currently it executes, but the change is not recorded in ckan

format_dict = pd.read_csv('https://docs.google.com/spreadsheets/d/1-fvtlOBQF9xZ-X8yttfRaYTFhlWrwR6AQatkPEKClck/export?format=csv')
testdataset = 'cjtest200915'

test = Dataset.read_from_hdx(testdataset)

testres = test.get_resources()
print("number of resources = "+str(len(testres)))
old_type = testres[0].get_file_type()
print ("old resource format = "+old_type)

old_type_lower_case = testres[0].get_file_type().lower()
print ("lowercased = "+old_type_lower_case)

new_type = format_dict.loc[format_dict['existing_format'] == old_type_lower_case,'approved_format'].iloc[0]
print ("new resource format (from mapping doc) = "+new_type)

#update with hdx python

testres[0].set_file_type(new_type)
print("resource format after setting = "+testres[0].get_file_type())

#this approach is the one that fails to update the ressource format
test.update_in_hdx(update_resources=True,hxl_update=False,ignore_check=True,operation='patch')

#this approach succeeds
#testres[0].update_in_hdx(operation='patch',ignore_check=True)

test = Dataset.read_from_hdx(testdataset)

testres = test.get_resources()
old_type = testres[0].get_file_type()
print ("resource format after updating = "+test.get_resources()[0].get_file_type())
mcarans commented 4 years ago

Fixed in 4.6.4. Please confirm and close or get back with issues.