`attachments` might not be defined here if `attachments=False` when the function is called. Initialize `attachments` with an empty dict like `history` and `comments` are up on line 208.