HDFGroup / h5serv

Reference service implementation of the HDF5 REST API
Other
168 stars 35 forks source link

PUT attribute String only fills in 1st character of value #98

Open ahalota opened 8 years ago

ahalota commented 8 years ago

I am adding an attribute to a dataset I created using the h5server.

The code I used is as follows, mostly copied from attributetest.py file:

def putLatestUpdate(year,month,day, uuid):        

    data = '-'.join([str(year),format(month,'02'),format(day,'02')])
    str_type = { 'charSet':   'H5T_CSET_ASCII', 
                     'class':  'H5T_STRING', 
                     'strPad': 'H5T_STR_NULLPAD', 
                     'length': 16}

    payload = {'type' : str_type, 'shape': (1,), 'value':data}
    req = helper.getEndpoint() + "/groups/" + uuid + "/attributes/latest_update"
    rsp = fc.requests.put(req, data=fc.json.dumps(payload), headers=myConfig['headers'])
    if (rsp.status_code != 201):
        print "Could not create latest date for",data
        return None
    rspJson = fc.json.loads(rsp.text)
    return rspJson

The code runs fine and does not show any error, but I noticed that it is only filling in the first value for the attribute. So, if I have year 2016, even though my data = '2016-06-10', the value in my attribute is '2'. If I change it to year = 1000, the value in my attribute is '1'.

Currently the uuid given is one for a group.

What am I doing wrong here?

ahalota commented 8 years ago

I found a solution in setting my value to be [data], i.e. a 1d array.

A little strange since the test file doesn't do this, but it fixed my problem.

ahalota commented 8 years ago

Ha, and of course now I see that there already IS a last modified attribute by default anyways. Well then...

jreadey commented 8 years ago

h5serv is expecting the data values to math the type and shape of the attribute. Is does seem like h5serv should give an error if a one-element is array is expected, but a scalar value is given. I'll re-open this as a reminder to investigate.

BTW, if you use a scalar shape, you'll be able to pass just the value. There are some examples in the attributetest.py file.