Fix serialisation of callbacks

Because the IDs of our callback and inbound SMS APIs were stored in
lists instead of directly on the serialised model they weren’t getting
cast to a string before trying to JSONify them. And JSON doesn’t know
what to do with a UUID object.

For some reason this was only affecting the endpoint for fetching
inbound SMS.
This commit is contained in:
Chris Hill-Scott
2020-06-26 16:31:49 +01:00
parent 8cef34d770
commit 8def7d0d3b
2 changed files with 29 additions and 1 deletions

View File

@@ -63,9 +63,16 @@ class UUIDsAsStringsMixin:
@post_dump()
def __post_dump(self, data):
for key, value in data.items():
if isinstance(value, UUID):
data[key] = str(value)
if isinstance(value, list):
data[key] = [
(str(item) if isinstance(item, UUID) else item)
for item in value
]
class BaseSchema(ma.ModelSchema):