@staticmethod
    def validate_field(value, field, new_record=True):
        """
        Validates a field value against a field metadata dictionary. Note: this
        is not yet intended to be a full validation. There are sure to be
        missing validation cases. Returns a list of validation errors.
        """
        errors = []

        if new_record:
            if not field['createable'] and value is not None:
                errors.append('Cannot create this field')
        else:
            if not field['updateable'] and value is not None:
                errors.append('Cannot update this field')

        if value is not None and field.get('restrictedPicklist'):
            values = [i['value']
                      for i in field['picklistValues'] if i['active']]
            if value not in values:
                errors.append('Bad value for restricted picklist field')

        if (new_record and value is None and not field['nillable'] and
                not field['defaultedOnCreate'] and field['type'] != 'boolean'):
            errors.append('This field is required')
        return errors
dataset/ETHPy150Open heroku/python-salesforce-client/salesforce/rest/base.py/SalesforceRestClientBase.validate_field/original