code: def create_slice(
      datasource_id: Optional[int] = None,
      datasource: Optional[SqlaTable] = None,
      name: Optional[str] = None,
      owners: Optional[list[User]] = None,
  ) -> Slice:
      name = name if name is not None else random_str()
      owners = owners if owners is not None else []
      datasource_type = "table"
      if datasource:
          return Slice(
              slice_name=name,
              table=datasource,
              owners=owners,
              datasource_type=datasource_type,
          )
  
      datasource_id = (
          datasource_id
          if datasource_id is not None
          else create_datasource_table_to_db(name=name + "_table").id
      )
  
      return Slice(
          slice_name=name,
          datasource_id=datasource_id,
          owners=owners,
          datasource_type=datasource_type,
      )
  
imports: import logging
  from typing import Optional
  from flask_appbuilder import Model
  from flask_appbuilder.security.sqla.models import User
  from superset import db
  from superset.connectors.sqla.models import SqlaTable, sqlatable_user
  from superset.models.core import Database
  from superset.models.dashboard import Dashboard, dashboard_slices, dashboard_user, DashboardRoles
  from superset.models.slice import Slice, slice_user
  from tests.integration_tests.dashboards.dashboard_test_utils import random_slug, random_str, random_title
label_desc: Use image node_id 5 for calling a global function with example usage: create_slice(datasource_id, datasource, name, owners) and returns: Slice, Slice