Device Inventory API fails when name contains single apostrophe symbol
Closed this issue · 1 comments
samrimington commented
I would like to retrieve the device ID for a device name containing a single apostrophe (').
Running the following results in a raised exception:
>>> from c8y_api.app import SimpleCumulocityApp
>>> app = SimpleCumulocityApp()
>>> app.device_inventory.get_all(name="Sam's Device")
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/sam/dev/cumulocity-python-api/c8y_api/model/inventory.py", line 194, in get_all
def get_all(self, type: str = None, name: str = None, owner: str = None, # noqa (type, parameters)
File "/home/sam/dev/cumulocity-python-api/c8y_api/model/_base.py", line 522, in _iterate
def _iterate(self, base_query, limit, parse_func):
File "/home/sam/dev/cumulocity-python-api/c8y_api/model/_base.py", line 518, in _get_page
def _get_page(self, base_query, page_number):
File "/home/sam/dev/cumulocity-python-api/c8y_api/_base_api.py", line 101, in get
def get(self, resource: str, params: dict = None, accept: str = None, ordered: bool = False) -> dict:
ValueError: Unable to perform GET request. Status: 422 Response:
{"error":"inventory/Invalid Data","message":"Find by filter query failed : Query 'name eq 'Sam's Device'' could not be understood. Please try again.","info":"https://www.cumulocity.com/guides/reference-guide/#a-name-error-reporting-a-error-reporting"}
If I apply OData conversion rules my end (i.e. use two apostrophes), the query works, like so:
>>> app.device_inventory.get_all(name="Sam''s Device")
[<c8y_api.model.manag...f1d1d0550>]
However I think this ought to be performed by c8y_api prior to sending a request.
chisou commented
Fixed in version 1.4