def METHOD_NAME(**kwargs):
    instance = kwargs["instance"]
    if instance._state.adding:
        update_previous_revision = (
            not instance.previous_revision
            and instance.attachment
            and instance.attachment.current_revision
            and instance.attachment.current_revision != instance
        )
        if update_previous_revision:
            instance.previous_revision = instance.attachment.current_revision
    if not instance.revision_number:
        try:
            previous_revision = instance.attachment.attachmentrevision_set.latest()
            instance.revision_number = previous_revision.revision_number + 1
        # NB! The above should not raise the below exception, but somehow
        # it does.
        except (AttachmentRevision.DoesNotExist, Attachment.DoesNotExist):
            instance.revision_number = 1