def insert(self, doc, synced=False):
        doc.id = self.get_next_id()
        doc.synced = synced
        try:
            self.db.docs.insert(doc)
        except Exception as e:
            raise DatabaseException(e)
        return doc
def exiter_as_until_exception(
        cls, new_exiter_fun: Callable[[Optional[Exiter]], Exiter]
    ) -> Iterator[None]:
        """Temporarily override the global exiter, except this will unset it when an exception
        happens."""
        previous_exiter = cls._exiter
        new_exiter = new_exiter_fun(previous_exiter)
        try:
            cls._reset_exiter(new_exiter)
            yield
        finally:
            cls._reset_exiter(previous_exiter)