code: def populate_owners(
      owner_ids: list[int] | None,
      default_to_user: bool,
  ) -> list[User]:
      """
      Helper function for commands, will fetch all users from owners id's
  
      :param owner_ids: list of owners by id's
      :param default_to_user: make user the owner if `owner_ids` is None or empty
      :raises OwnersNotFoundValidationError: if at least one owner id can't be resolved
      :returns: Final list of owners
      """
      owner_ids = owner_ids or []
      owners = []
      if not owner_ids and default_to_user:
          return [g.user]
      if not (
          security_manager.is_admin() or get_user_id() in owner_ids
      ):
          # make sure non-admins can't remove themselves as owner by mistake
          owners.append(g.user)
      for owner_id in owner_ids:
          owner = security_manager.get_user_by_id(owner_id)
          if not owner:
              raise OwnersNotFoundValidationError()
          owners.append(owner)
      return owners
  
file_path: superset/superset/commands/utils.py
imports: from __future__ import annotations
  from typing import TYPE_CHECKING
  from flask import g
  from flask_appbuilder.security.sqla.models import Role, User
  from superset import security_manager
  from superset.commands.exceptions import DatasourceNotFoundValidationError, OwnersNotFoundValidationError, RolesNotFoundValidationError
  from superset.daos.datasource import DatasourceDAO
  from superset.daos.exceptions import DatasourceNotFound
  from superset.extensions import db
  from superset.utils.core import DatasourceType, get_user_id
label_desc: Use image node_id 1 for calling a global function with example usage: populate_owners(owner_ids, default_to_user) and returns: owners, list