<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def upsert(self, doc, namespace, timestamp):
 """Adds a document to the doc dict. """


        # Allow exceptions to be triggered (for testing purposes)
        if doc.get("_upsert_exception"):
            raise Exception("upsert exception")

        doc_id = doc["_id"]
        self.doc_dict[doc_id] = Entry(doc=doc, ns=namespace, ts=timestamp)