code: def get_effective_user(self, url, user_name=None):
          
          effective_username = None
          if self.impersonate_user:
              effective_username = url.username
              if user_name:
                  effective_username = user_name
              elif (
                  hasattr(g, 'user') and hasattr(g.user, 'username') and
                  g.user.username is not None
              ):
                  effective_username = g.user.username
          return effective_username
docs: Get the effective user, especially during impersonation.
          :param url: SQL Alchemy URL object
          :param user_name: Default username
          :return: The effective username