def create(self) -> Key: entry = KeyValueEntry( resource=self.resource.value, value=pickle.dumps(self.value), created_on=datetime.now(), created_by_fk=get_user_id(), expires_on=self.expires_on, ) if self.key is not None: try: if isinstance(self.key, UUID): entry.uuid = self.key else: entry.id = self.key except ValueError as ex: raise KeyValueCreateFailedError() from ex db.session.add(entry) db.session.commit() return Key(id=entry.id, uuid=entry.uuid)
def create(self) -> str: entry = KeyValueEntry( resource=self.resource, value=pickle.dumps(self.value), created_on=datetime.now(), created_by_fk=None if self.actor is None or self.actor.is_anonymous else self.actor.id, expires_on=self.expires_on, ) if self.key is not None: try: if self.key_type == "uuid": entry.uuid = UUID(self.key) else: entry.id = int(self.key) except ValueError as ex: raise KeyValueCreateFailedError() from ex db.session.add(entry) db.session.commit() return extract_key(entry, self.key_type)