@classmethod
  @gen.engine
  def MakeFriendAndUpdate(cls, client, user_id, friend_dict, callback):
    """Ensures that the given user has at least a one-way friend relationship with the given
    friend. Updates the friend relationship attributes with those given in "friend_dict".
    """
    from viewfinder.backend.db.user import User

    friend = yield gen.Task(Friend.Query, client, user_id, friend_dict['user_id'], None, must_exist=False)

    if friend is None:
      # Ensure that the friend exists as user in the system.
      friend_user = yield gen.Task(User.Query, client, friend_dict['user_id'], None, must_exist=False)
      if friend_user is None:
        raise NotFoundError('User %d does not exist.' % friend_dict['user_id'])

      # Create a one-way friend relationship from the calling user to the friend user.
      friend = Friend.CreateFromKeywords(user_id=user_id, friend_id=friend_dict['user_id'], status=Friend.FRIEND)

    # Update all given attributes.
    assert friend_dict['user_id'] == friend.friend_id, (friend_dict, friend)
    for key, value in friend_dict.iteritems():
      if key != 'user_id':
        assert key in Friend.FRIEND_ATTRIBUTES, friend_dict
        setattr(friend, key, value)

    yield gen.Task(friend.Update, client)
    callback()
dataset/ETHPy150Open viewfinderco/viewfinder/backend/db/friend.py/Friend.MakeFriendAndUpdate/original