code: def get_mapper(row):
      
      try:
          mapper = getattr(row, '__mapper__')
      except AttributeError as e:
          e.args = ('Row must be instance of the declarative base class, '
                    'got %s instead' % type(row).__name__,)
          raise
  
      return mapper
docs: Tries to get the mapper from a row instance.
      http://docs.sqlalchemy.org/en/latest/orm/tutorial.html#declare-a-mapping
  
      :param row: instance of the declarative base class
  
      :return: instance of :class:`sqlalchemy.orm.mapper.Mapper`