code: def switch_schema(task, kwargs, **kw):
      
      # Lazily load needed functions, as they import django model functions which
      # in turn load modules that need settings to be loaded and we can't
      # guarantee this module was loaded when the settings were ready.
      from .compat import get_public_schema_name, get_tenant_model
  
      old_schema = (connection.schema_name, connection.include_public_schema)
      setattr(task, '_old_schema', old_schema)
  
      schema = (
          get_schema_name_from_task(task, kwargs) or
          get_public_schema_name()
      )
  
      # If the schema has not changed, don't do anything.
      if connection.schema_name == schema:
          return
  
      if connection.schema_name != get_public_schema_name():
          connection.set_schema_to_public()
  
      if schema == get_public_schema_name():
          return
  
      tenant = get_tenant_model().objects.get(schema_name=schema)
      connection.set_tenant(tenant, include_public=True)
docs: Switches schema of the task, before it has been run.