Object of type GlideElement is not JSON serializable
Closed this issue · 4 comments
I'm using PySNC to create records in my ServiceNow instance.
Used Python version: 3.10
Last known working version: 1.0.7
Bug seen in versions: 1.1.2, 1.1.3
My code worked with version 1.0.7 and then stopped working in 1.1.2 (and still didn't work in 1.1.3). I'm getting the following exception when calling GlideRecord.insert:
Traceback (most recent call last):
File "/home/vsts/work/1/s/create-ticket.py", line 147, in <module>
call.insert()
File "/home/vsts/work/1/s/antenv/lib/python3.10/site-packages/pysnc/record.py", line 538, in insert
response = self._client.table_api.post(self)
File "/home/vsts/work/1/s/antenv/lib/python3.10/site-packages/pysnc/client.py", line 224, in post
return self._send(req)
File "/home/vsts/work/1/s/antenv/lib/python3.10/site-packages/pysnc/client.py", line 176, in _send
request = self.session.prepare_request(req)
File "/home/vsts/work/1/s/antenv/lib/python3.10/site-packages/requests/sessions.py", line 484, in prepare_request
p.prepare(
File "/home/vsts/work/1/s/antenv/lib/python3.10/site-packages/requests/models.py", line 371, in prepare
self.prepare_body(data, files, json)
File "/home/vsts/work/1/s/antenv/lib/python3.10/site-packages/requests/models.py", line 511, in prepare_body
body = complexjson.dumps(json, allow_nan=False)
File "/opt/hostedtoolcache/Python/3.10.11/x64/lib/python3.10/json/__init__.py", line 238, in dumps
**kw).encode(obj)
File "/opt/hostedtoolcache/Python/3.10.11/x64/lib/python3.10/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/opt/hostedtoolcache/Python/3.10.11/x64/lib/python3.10/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "/opt/hostedtoolcache/Python/3.10.11/x64/lib/python3.10/json/encoder.py", line 179, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type GlideElement is not JSON serializable
i have an idea, here, i'll see if i can reproduce in tests and fix asap. Thanks for reporting
@ABNAMRO-APIM should be fixed in 1.1.4, let me know
I confirm it did fix the issue. Thanks for the quick response!
Just a note - in 1.0.7 the following code worked:
call = client.GlideRecord('u_call')
# ...
call.insert()
description = description.replace('placeholder', call.number)
In 1.1.4 it throws an exception, because call.number doesn't seem to be a string anymore:
call.description = description.replace('placeholder', call.number)
TypeError: replace() argument 2 must be str, not GlideElement
I fixed that by using call.number.get_value()
, but I just wanted to let you know it looks like a breaking change