code: def get_max_id(cls, session):
          id_base = None
          for c in [cls] + list(cls.__bases__):
              for base_class in c.__bases__:
                  if base_class.__name__ == 'Base':
                      if id_base is None:
                          id_base = c
                      else:
                          raise RuntimeError("Multiple base object classes for class " + cls.__name__)
          if id_base is None:
              raise RuntimeError("Error searching for base class of " + cls.__name__)
          max_id = session.query(func.max(id_base.id)).scalar()
          if max_id is None:
              max_id = 0
          return max_id