Ensuring that requesting to update the metadata with values that do not serialize as a JSON object raises an exception in the client#1408
Conversation
|
New Issues (1)Checkmarx found the following issues in this Pull Request
Fixed Issues (1)Great job! The following issues were fixed in this Pull Request
Communicate with Checkmarx by submitting a PR comment with @Checkmarx followed by one of the supported commands. Learn about the supported commands here. |
|
Thanks for this fix! Indeed, it looks like we accept any JSON-serializable type, where we should insist on only things that serialize as a JSON object. In Python, I've been trained to be suspicious of Here's a real example of a dict-like object in the Python standard library that is not a In [1]: from tiled.client import simple
In [2]: import collections
In [3]: c = simple()
Tiled version 0.2.10
http://127.0.0.1:43145/api/v1?api_key=3a3359cdbc50ed74
In [4]: d1 = {'a': 1}
In [5]: d2 = {'b': 2}
In [6]: d = collections.ChainMap(d1, d2)
In [7]: d
Out[7]: ChainMap({'a': 1}, {'b': 2})
In [8]: isinstance(d, dict)
Out[8]: False
In [9]: x = c.write_array([1,2,3], key='x')
In [10]: x.update_metadata(metadata=d)
In [11]: x
Out[11]: <ArrayClient shape=(3,) chunks=((3,)) dtype=int64>
In [12]: x.metadata
Out[12]: {'a': 1, 'b': 2}
In [13]: c['x'].metadata
Out[13]: {'a': 1, 'b': 2}
In [15]: import collections.abcOne path is to check against the abstract base case (abc) for "mappings" which is broader than In [16]: isinstance(d, collections.abc.Mapping)
Out[16]: True |
|
Sorry, I should have mentioned in my previous comment: Would you please add a test to verify the new behavior for a range of invalid inputs? Look for existing tests that exercise |
|
Hi! Thank you for looking it over! I added the pytests, let me know if there is anything else I should change. |


This PR is intended to fix the issue where trying to update the metadata with update_metadata() with a parameter that is not of the right type (will serialize as a JSON object) allows for the modification but then causes server errors when trying to access. To fix this issue, this PR checks to see if the metadata does not match the dictionary type when it contains a value with calling update_metadata(metadata=value).
This issue was initially brought up in #1226.
Checklist