From 78e87857e36f68b163fce37a8c8e8bf7bc001fa4 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Fri, 15 Jan 2021 13:15:00 +0000 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20serialize=20nullable=20UUID=20c?= =?UTF-8?q?olumns=20to=20'None'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We should return a proper `None` instead, so it gets JSONified as `null` and returns what you’d expect when doing `bool(model.field)` --- app/models.py | 13 +++++++++---- app/utils.py | 4 ++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/models.py b/app/models.py index f8bea361e..707d2a431 100644 --- a/app/models.py +++ b/app/models.py @@ -36,7 +36,12 @@ from app.hashing import ( check_hash ) from app import db, encryption -from app.utils import DATETIME_FORMAT, DATETIME_FORMAT_NO_TIMEZONE, get_dt_string_or_none +from app.utils import ( + DATETIME_FORMAT, + DATETIME_FORMAT_NO_TIMEZONE, + get_dt_string_or_none, + get_uuid_string_or_none, +) from app.history_meta import Versioned @@ -2296,9 +2301,9 @@ class BroadcastMessage(db.Model): 'cancelled_at': get_dt_string_or_none(self.cancelled_at), 'updated_at': get_dt_string_or_none(self.updated_at), - 'created_by_id': str(self.created_by_id), - 'approved_by_id': str(self.approved_by_id), - 'cancelled_by_id': str(self.cancelled_by_id), + 'created_by_id': get_uuid_string_or_none(self.created_by_id), + 'approved_by_id': get_uuid_string_or_none(self.approved_by_id), + 'cancelled_by_id': get_uuid_string_or_none(self.cancelled_by_id), } diff --git a/app/utils.py b/app/utils.py index df12e0ac1..a5a2d15f2 100644 --- a/app/utils.py +++ b/app/utils.py @@ -150,5 +150,9 @@ def get_dt_string_or_none(val): return val.strftime(DATETIME_FORMAT) if val else None +def get_uuid_string_or_none(val): + return str(val) if val else None + + def format_sequential_number(sequential_number): return format(sequential_number, "x").zfill(8)