Don’t serialize nullable UUID columns to 'None'

We should return a proper `None` instead, so it gets JSONified as `null`
and returns what you’d expect when doing `bool(model.field)`
This commit is contained in:
Chris Hill-Scott
2021-01-15 13:15:00 +00:00
parent fe420448e1
commit 78e87857e3
2 changed files with 13 additions and 4 deletions

View File

@@ -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),
}

View File

@@ -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)