def object_compat(function):
 @functools.wraps(function)
 def decorated_function(self, context, *args, **kwargs):
  def _load_instance(instance_or_dict):
   if isinstance(instance_or_dict, dict):
    metas = [meta for meta in ('metadata', 'system_metadata') if (meta in instance_or_dict)]
    instance = objects.Instance._from_db_object(context, objects.Instance(), instance_or_dict, expected_attrs=metas)
    instance._context = context
    return instance
   return instance_or_dict
  try:
   kwargs['instance'] = _load_instance(kwargs['instance'])
  except KeyError:
   args = ((_load_instance(args[0]),) + args[1:])
  migration = kwargs.get('migration')
  if isinstance(migration, dict):
   migration = objects.Migration._from_db_object(context.elevated(), objects.Migration(), migration)
   kwargs['migration'] = migration
  return function(self, context, *args, **kwargs)
 return decorated_function

def object_compat ( function ) : @ functools . wraps ( function ) def decorated_function ( self , context , * args , ** kwargs ) : def _load_instance ( instance_or_dict ) : if isinstance ( instance_or_dict , dict ) : metas = [ meta for meta in ( 'metadata' , 'system_metadata' ) if ( meta in instance_or_dict ) ] instance = objects . Instance . _from_db_object ( context , objects . Instance ( ) , instance_or_dict , expected_attrs = metas ) instance . _context = context return instance return instance_or_dict try : kwargs [ 'instance' ] = _load_instance ( kwargs [ 'instance' ] ) except KeyError : args = ( ( _load_instance ( args [ 0 ] ) , ) + args [ 1 : ] ) migration = kwargs . get ( 'migration' ) if isinstance ( migration , dict ) : migration = objects . Migration . _from_db_object ( context . elevated ( ) , objects . Migration ( ) , migration ) kwargs [ 'migration' ] = migration return function ( self , context , * args , ** kwargs ) return decorated_function
wraps a method that expects a new-world instance this provides compatibility for callers passing old-style dict instances .