def Transform(self, client, photo, callback):
    from viewfinder.backend.storage.s3_object_store import S3ObjectStore

    def _SetPhotoSizeValues(size_values):
      tn_size, med_size, full_size, orig_size = size_values

      assert photo.tn_size == tn_size or photo.tn_size is None, photo
      photo.tn_size = tn_size

      assert photo.med_size == med_size or photo.med_size is None, photo
      photo.med_size = med_size

      assert photo.full_size == full_size or photo.full_size is None, photo
      photo.full_size = full_size

      assert photo.orig_size == orig_size or photo.orig_size is None, photo
      photo.orig_size = orig_size

      self._LogUpdate(photo)

      if Version._mutate_items:
        photo.Update(client, partial(callback, photo))
      else:
        callback(photo)

    def _OnListKeys(result):
      def _GetSizeOrNone(files, suffix):
        fname = photo.photo_id + '.' + suffix
        if fname in files:
          return int(files[fname]['Size'])
        else:
          return None

      if len(result) > 0:
        _SetPhotoSizeValues((_GetSizeOrNone(result, 't'), _GetSizeOrNone(result, 'm'),
                            _GetSizeOrNone(result, 'f'), _GetSizeOrNone(result, 'o')))
      else:
        logging.info('No files found in S3 for photo %s' % photo.photo_id)
        callback(photo)

    def _ListPhotoMetadata():
      object_store = S3ObjectStore('photos-viewfinder-co')
      object_store.ListKeyMetadata(_OnListKeys, prefix=photo.photo_id + '.',
                                   fields=['Size', 'Key'])

    client_data = photo.client_data
    # the assumption is that is we have the tn_size field set, all other
    # sizes will be as well. db analysis shows this to be currently true.
    if client_data is None or 'tn_size' not in client_data:
      if not Version._allow_s3_queries:
        callback(photo)
        return
      # Extract sizes from S3.
      _ListPhotoMetadata()
    else:
      # Extract sizes from client_data.
      _SetPhotoSizeValues((int(client_data['tn_size']), int(client_data['med_size']),
                          int(client_data['full_size']), int(client_data['orig_size'])))
dataset/ETHPy150Open viewfinderco/viewfinder/backend/db/versions.py/FillFileSizes.Transform/original