splunk / splunk-sdk-python

Splunk Software Development Kit for Python
http://dev.splunk.com
Apache License 2.0
698 stars 370 forks source link

Treat KVStoreCollectionData Data Consistently #355

Closed malvidin closed 3 years ago

malvidin commented 4 years ago

The KVStoreCollectionData response from query_by_id is a dict. However, this requires the user to convert the dict to a string before passing it back to any function that pushes data to the collection.

Any dict returned should be able to be returned directly to other functions that modify content in the KV store. Adding something like the following would allow backward compatibility, while permitting more flexibility to deal with the object directly without having to coerce the returned data into a string before passing it back to the KV store.

    :type data: ``string`` or ``dict``
   ... 
   if isinstance(data, dict):
       data = json.dumps(data) 
   ...

...

data = collection.data.query_by_id(id="kv_store_id")
data['key'] = 'value'
collection.data.update(id='kv_store_id', data=data) == {'_key': 'kv_store_id'}
# Instead of having the API user repeatedly call json.dumps()
# collection.data.update(id='kv_store_id', data=json.dumps(data)) == {'_key': 'kv_store_id'}

Another option would be creating a new function that wraps the insert and update functions. Either way, I expect the KVStoreCollectionData POST functions would directly accept the data it returned from its GET functions.

ashah-splunk commented 3 years ago

Hi @malvidin , Thanks for bringing it up. We have considered your suggestion and the changes will be available in the next release. Reference PR

ashah-splunk commented 3 years ago

Hi @malvidin , we have a new SDK release 1.6.17 with the proposed changes. Would request you to try with the latest SDK version. Let us know in case if you face any issue with the change.