markhoerth / dremio_client

Apache License 2.0
31 stars 25 forks source link

Need to set "state" to null to be able to modify a source acl #217

Closed insatomcat closed 3 years ago

insatomcat commented 3 years ago

Description

When trying to modify the ACL of a SOURCE after creating it, I get the following error :

Requested object does not exist on entity : 400 Client Error: Bad Request for url: https://mathis-integration.rte-france.com:443/api/v3/catalog/d251df8f-1515-4c25-b9d6-4318956742d9

the code is as follows:

#SOURCE CREATION

source = 'SOURCE1'
NewSource='{"entityType": "source", "name": "'+ source + '", "description": "essai", "type": "NAS", "config": {"path": "/mnt/nasdata/test/", "allowCreateDrop": true}}'
d=catalog.add(item=json.loads(NewSource))
catalog[source]._dirty = True
catalog[source].commit()

#SOURCE ACL MODIFICATION

a = catalog.SOURCE1.get()
b = a.meta
b.accessControlList = json.loads('{"users": [{"id": "user1", "permissions": ["READ", "WRITE"]}], "groups": null, "version": null}')
setattr(a,"meta",b)
a._dirty = True
a.commit()

What I Did

The problem can be worked around in two ways. Either re-init the client between the creation and the modification:

client = init()
catalog = client.data

Or (and I found this because I checked the difference between "b" with or without the re-init) by removing the "state" attribute in the SourceMetadata before commiting (note the "b.state = None" line):

a = catalog.SOURCE1.get()
b = a.meta
b.accessControlList = json.loads('{"users": [{"id": "user1", "permissions": ["READ", "WRITE"]}], "groups": null, "version": null}')
b.state = None
setattr(a,"meta",b)
a._dirty = True
a.commit()

Note that this is only needed for sources (and maybe spaces I didn't test) but I don't have to do this to change an ACL on an folder or a VDS.

Maybe it's some dremio specificity that has not been taken into account by dremio_client ?

What do you think ?

Thanks.

rymurr commented 3 years ago

Thanks for the detailed bug report @insatomcat !

Has this been a new thing? Wonder if it changed in a recent release. What is interesting is we should be removing the state attribute on posts https://github.com/rymurr/dremio_client/blob/master/dremio_client/model/data.py#L553

Is the API call a PUT maybe?

Either way, we should definitely strip out the state attribute before returning to Dremio

insatomcat commented 3 years ago

It's definetely a PUT, since it's a modification of an existing catalog entity https://docs.dremio.com/rest-api/catalog/put-catalog-id/ https://github.com/rymurr/dremio_client/blob/9c6bf83a9260a9114ff046b02ae6507f9754a353/dremio_client/model/data.py#L352

Let me propose fix #221