def update(self, instance):
        instance_id = self.get_instance_id(instance)
        if not instance.metadata:
            raise InvalidMetaBlockException(
                "Instance %s didn't have a meta block!" % instance_id)

        if (instance.metadata.instanceID and
                instance.metadata.instanceID != instance_id):
            # we never want to differentiate between these two ids
            raise InvalidMetaBlockException(
                "Instance had doc id (%s) different "
                "from meta instanceID (%s)!" % (
                    instance_id, instance.metadata.instanceID)
            )

        if self.instance_id and self.instance_id != instance_id:
            # we never allow updates to change the instance ID
            raise InvalidFormUpdateException(
                "Tried to update formdata %s with different "
                "instance id %s!" % (self.instance_id, instance_id)
            )

        if not instance.metadata.timeEnd or not instance.metadata.timeStart:
            # we don't allow these fields to be empty
            raise InvalidFormUpdateException(
                "No timeStart or timeEnd found in instance %s!" % (
                    instance_id)
            )

        if not instance.received_on:
            # we don't allow this field to be empty
            raise InvalidFormUpdateException(
                "No received_on date found in instance %s!" % (
                    instance_id)
            )

        self.domain = instance.domain
        self.received_on = instance.received_on

        self.instance_id = instance_id
        self.time_start = instance.metadata.timeStart
        self.time_end = instance.metadata.timeEnd
        td = instance.metadata.timeEnd - instance.metadata.timeStart
        self.duration = td.seconds + td.days * 24 * 3600
        self.device_id = instance.metadata.deviceID
        self.user_id = instance.metadata.userID
        self.username = instance.metadata.username
        self.app_id = instance.app_id or MISSING_APP_ID
        self.xmlns = instance.xmlns
Update this object based on an XFormInstance doc
dataset/ETHPy150Open dimagi/commcare-hq/corehq/apps/sofabed/models.py/FormData.update