The aim is to add good enough logging to UserDeleteService such that if a user was accidentally deleted (or if a bug caused UserDeleteService to delete stuff that it shouldn't, etc) we'd have enough information in the logs to assess what happened and to recover the accidentally deleted data from a backup of the DB.
The logging should also incidentally make monitoring and debugging generally easier.
Notes:
__repr__()'s on all model classes that're nice and short, include the primary key, and don't include any sensitive information. And then log model objects with %r or {obj!r} so that __repr__() is used not __str__().
When rendering lists of things from the DB into log message strings it's good to sort the things. This makes the app's behaviour more predictable: always logging things in alphabetical order. And makes it easier to write non-flakey test assertions.
It can be useful to have helper functions to log things in a consistent way. For example all the UserDeleteService log messages in this PR start with "Purging {user!r} - " and when DB rows have been deleted or updated there's always a comma-separated list of the IDs of the affected rows.
Demo:
The aim is to add good enough logging to
UserDeleteService
such that if a user was accidentally deleted (or if a bug causedUserDeleteService
to delete stuff that it shouldn't, etc) we'd have enough information in the logs to assess what happened and to recover the accidentally deleted data from a backup of the DB.The logging should also incidentally make monitoring and debugging generally easier.
Notes:
__repr__()
's on all model classes that're nice and short, include the primary key, and don't include any sensitive information. And then log model objects with%r
or{obj!r}
so that__repr__()
is used not__str__()
.When rendering lists of things from the DB into log message strings it's good to sort the things. This makes the app's behaviour more predictable: always logging things in alphabetical order. And makes it easier to write non-flakey test assertions.
It can be useful to have helper functions to log things in a consistent way. For example all the
UserDeleteService
log messages in this PR start with"Purging {user!r} - "
and when DB rows have been deleted or updated there's always a comma-separated list of the IDs of the affected rows.