Sets the value of the given (possibly dotted) attribute for the given
    object to the given value.

    :raises AttributeError: If any of the parents on the nested attribute's
      name path are `None`.

def set_nested_attribute(obj, attribute, value):
    """
    Sets the value of the given (possibly dotted) attribute for the given
    object to the given value.

    :raises AttributeError: If any of the parents on the nested attribute's
      name path are `None`.
    """
    parent, attr = resolve_nested_attribute(obj, attribute)
    if parent is None:
        raise AttributeError('Can not set attribute "%s" on None value.'
                             % attr)
    setattr(parent, attr, value)