@classmethod
  def MaybeMigrate(cls, client, original_item, versions, callback):
    """Migrates the data in one table row ('item') by advancing
    'item's version via successive data migrations. If 'item' does not
    have a version yet, all data migrations are applied. If item's
    version is current, does nothing. Return the migrated object if
    mutations are enabled, or the original object if not. Take care
    if the migration changes the primary key; the caller might fetch
    an object using one primary key, but get back an object with a
    different migrated primary key!
    """
    def _Migrate(start_rank, mutate_item):
      last_rank = 0
      for version in versions:
        if version.rank < start_rank:
          last_rank = version.rank
          continue
        assert version.rank > last_rank, \
            'tags listed out of order (! %d > %d)' % (version.rank, last_rank)
        last_rank = version.rank
        item_version = mutate_item._version or 0
        if item_version < version.rank:
          logging.debug('upgrading item from %s to version %s' %
                        (type(mutate_item)._table.name, version.__class__.__name__))
          mutate_item._version = version.rank

          # If Transform fails, retry several times before giving up.
          transform_callback = partial(_Migrate, last_rank + 1)
          retry.CallWithRetryAsync(Version._migrate_retry_policy,
                                   version.Transform,
                                   client,
                                   mutate_item,
                                   callback=transform_callback)
          return

      callback(mutate_item if Version._mutate_items else original_item)

    _Migrate(0, original_item if Version._mutate_items else original_item._Clone())
dataset/ETHPy150Open viewfinderco/viewfinder/backend/db/versions.py/Version.MaybeMigrate/original