notification.personalisation now always returns an empty dict

There are a variety of ways a notification can be created - via the
API, via CSV, via one-off messages, via the same but sent as a test -
the point is, there are lots of entry points, and lots of inconsistency
about how personalisation may be sent in. If there are no
personalisation options in the template, we may get either `None` or
`{}` - if the value is None, to avoid an error in our encryption lib,
we just store None in the database.

THIS ENDS NOW!

We've had some problems on the front-end that is caused by
notifications having the `None` value. This commit changes the
personalisation property getter and setter to store/return `{}`
rather than None.
This commit is contained in:
Leo Hemsted
2017-07-03 16:04:21 +01:00
committed by venusbb
parent d6c69bf437
commit 38bb4ad6c2
2 changed files with 23 additions and 3 deletions

View File

@@ -830,12 +830,11 @@ class Notification(db.Model):
def personalisation(self):
if self._personalisation:
return encryption.decrypt(self._personalisation)
return None
return {}
@personalisation.setter
def personalisation(self, personalisation):
if personalisation:
self._personalisation = encryption.encrypt(personalisation)
self._personalisation = encryption.encrypt(personalisation or {})
def completed_at(self):
if self.status in NOTIFICATION_STATUS_TYPES_COMPLETED: