def get_game(model):
  """ Return a Game object.

  Args:
    model: A database model that is either a GameInstance or Game.

  Returns:
    Either returns model or its parent if either of them is a Game
    object.

  Raises:
    ValueError if either model or its parent is not a Game object.
  """
  if model.__class__.__name__ == 'GameInstance':
    model = model.parent()
  if model.__class__.__name__ == 'Game':
    return model
  raise ValueError('Invalid model passed to get_game')