-
Notifications
You must be signed in to change notification settings - Fork 15
Cancelled Elections and Soft Deletes
Sometimes an election is scheduled and then cancelled. Usually this is either because the election is uncontested so no poll is held, or because one of the candidates dies during the campaign period. Generally when an election is cancelled due to death of a candidate the same election is rescheduled a few weeks later. For example:
- local.forest-of-dean.newent-taynton.2019-05-02 was cancelled and replaced by another ballot
- local.wychavon.bretforton-and-offenham.2019-05-02 was uncontested
When this happens, we set the cancelled flag on the election via /admin. This means its still discoverable via the front end and other services that rely on the data can surface this information.
We can also optionally:
- Mark another election object as the replacement for this election
- Associate a metadata object with this election to provide more information
Sometimes we've accidentally approved an election that was never scheduled and shouldn't have been created in the first place (usually due to a human data entry error). In this case, we don't want to mark it as cancelled because it was never scheduled in the first place. We want to mark it as deleted (but not actually fully delete it). This allows YNR, WCIVF, etc to pick up the deletion and propagate it.
To do this, we add a ModerationHistory event with the status 'Deleted' via /admin to any applicable elections (including ballot, group etc). ModerationHistory is an append-only log, so we can only add history events.
There is also an admin action to soft-delete elections in bulk. This can be found in the Election admin and works in the same way other admin actions work. A MorderationHistory
event with status of "Deleted" will be created for all elections selected.
When we do this, the deleted election is no longer discoverable via the front end, but we can use an API query to find out about deleted elections. If we ever needed to un-delete an election, we could add another history event to the log with the status 'Approved'.
Only elections with the 'Approved' status are visible to Elections.public_objects
. See https://github.com/DemocracyClub/EveryElection/blob/cfe79ec3b8d5b9da057ff3f3b84f9ff5841e0749/every_election/apps/elections/managers.py#L52-L75
Some more things to consider when soft deleting elections:
- Soft-deleting an election object which has children won't soft delete the children. For example, soft deleting the
parl.2019-12-12
would not soft delete the elections for each constituency - these would all need to be deleted individually. In this circumstance, the bulk soft delete admin action will be most useful. - In order to un-soft delete an election, you must create a new
ModerationHistory
event with an "approved" status. - After soft-deleting an election, the admin actions to alter the
current
status will still be available for these elections, however they will do nothing. See the note above above what makes an Election object returned in theElection.public_objects
.