class_docstr: This entity may change or be removed in a future release without warning.
  SQLAlchemy compliant backend store for tracking meta data for MLflow entities. MLflow
  supports the database dialects ``mysql``, ``mssql``, ``sqlite``, and ``postgresql``.
  As specified in the
  `SQLAlchemy docs <https://docs.sqlalchemy.org/en/latest/core/engines.html#database-urls>`_ ,
  the database URI is expected in the format
  ``<dialect>+<driver>://<username>:<password>@<host>:<port>/<database>``. If you do not
  specify a driver, SQLAlchemy uses a dialect's default driver.
  
  This store interacts with SQL store using SQLAlchemy abstractions defined for MLflow entities.
  :py:class:`mlflow.store.model_registry.models.RegisteredModel` and
  :py:class:`mlflow.store.model_registry.models.ModelVersion`
docstr: Update model version stage.
  
  :param name: Registered model name.
  :param version: Registered model version.
  :param stage: New desired stage for this model version.
  :param archive_existing_versions: If this flag is set to ``True``, all existing model
      versions in the stage will be automatically moved to the "archived" stage. Only valid
      when ``stage`` is ``"staging"`` or ``"production"`` otherwise an error will be raised.
  
  :return: A single :py:class:`mlflow.entities.model_registry.ModelVersion` object.
docstr_tok: ["Update","model","version","stage",".",":","param","name",":","Registered","model","name",".",":","param","version",":","Registered","model","version",".",":","param","stage",":","New","desired","stage","for","this","model","version",".",":","param","archive_existing_versions",":","If","this","flag","is","set","to","``","True","``",",","all","existing","model","versions","in","the","stage","will","be","automatically","moved","to","the","``","archived","''","stage",".","Only","valid","when","``","stage","``","is","``","``","staging","''","``","or","``","``","production","''","``","otherwise","an","error","will","be","raised",".",":","return",":","A","single",":","py",":","class",":","`","mlflow.entities.model_registry.ModelVersion","`","object","."]
code: def transition_model_version_stage(
      self, name, version, stage, archive_existing_versions
  ):
      """
      Update model version stage.
  
      :param name: Registered model name.
      :param version: Registered model version.
      :param stage: New desired stage for this model version.
      :param archive_existing_versions: If this flag is set to ``True``, all existing model
          versions in the stage will be automatically moved to the "archived" stage. Only valid
          when ``stage`` is ``"staging"`` or ``"production"`` otherwise an error will be raised.
  
      :return: A single :py:class:`mlflow.entities.model_registry.ModelVersion` object.
      """
      is_active_stage = (
          get_canonical_stage(stage)
          in DEFAULT_STAGES_FOR_GET_LATEST_VERSIONS
      )
      if archive_existing_versions and not is_active_stage:
          msg_tpl = (
              "Model version transition cannot archive existing model versions "
              "because '{}' is not an Active stage. Valid stages are {}"
          )
          raise MlflowException(
              msg_tpl.format(
                  stage, DEFAULT_STAGES_FOR_GET_LATEST_VERSIONS
              )
          )
  
      with self.ManagedSessionMaker() as session:
          last_updated_time = get_current_time_millis()
  
          model_versions = []
          if archive_existing_versions:
              conditions = [
                  SqlModelVersion.name == name,
                  SqlModelVersion.version != version,
                  SqlModelVersion.current_stage
                  == get_canonical_stage(stage),
              ]
              model_versions = (
                  session.query(SqlModelVersion)
                  .filter(*conditions)
                  .all()
              )
              for mv in model_versions:
                  mv.current_stage = STAGE_ARCHIVED
                  mv.last_updated_time = last_updated_time
  
          sql_model_version = self._get_sql_model_version(
              session=session, name=name, version=version
          )
          sql_model_version.current_stage = get_canonical_stage(stage)
          sql_model_version.last_updated_time = last_updated_time
          sql_registered_model = sql_model_version.registered_model
          sql_registered_model.last_updated_time = last_updated_time
          session.add_all(
              [*model_versions, sql_model_version, sql_registered_model]
          )
          return self._populate_model_version_aliases(
              session, name, sql_model_version.to_mlflow_entity()
          )
  
imports: import logging
  import urllib
  import sqlalchemy
  from sqlalchemy.future import select
  import mlflow.store.db.utils
  from mlflow.entities.model_registry.model_version_stages import ALL_STAGES, DEFAULT_STAGES_FOR_GET_LATEST_VERSIONS, STAGE_ARCHIVED, STAGE_DELETED_INTERNAL, get_canonical_stage
  from mlflow.exceptions import MlflowException
  from mlflow.protos.databricks_pb2 import INVALID_PARAMETER_VALUE, INVALID_STATE, RESOURCE_ALREADY_EXISTS, RESOURCE_DOES_NOT_EXIST
  from mlflow.store.artifact.utils.models import _parse_model_uri
  from mlflow.store.entities.paged_list import PagedList
  from mlflow.store.model_registry import SEARCH_MODEL_VERSION_MAX_RESULTS_DEFAULT, SEARCH_MODEL_VERSION_MAX_RESULTS_THRESHOLD, SEARCH_REGISTERED_MODEL_MAX_RESULTS_DEFAULT, SEARCH_REGISTERED_MODEL_MAX_RESULTS_THRESHOLD
  from mlflow.store.model_registry.abstract_store import AbstractStore
  from mlflow.store.model_registry.dbmodels.models import SqlModelVersion, SqlModelVersionTag, SqlRegisteredModel, SqlRegisteredModelAlias, SqlRegisteredModelTag
  from mlflow.utils.search_utils import SearchModelUtils, SearchModelVersionUtils, SearchUtils
  from mlflow.utils.time import get_current_time_millis
  from mlflow.utils.uri import extract_db_type_from_uri
  from mlflow.utils.validation import _validate_model_alias_name, _validate_model_name, _validate_model_version, _validate_model_version_tag, _validate_registered_model_tag, _validate_tag_name
label_desc: Use image node_id 28 for calling the SqlAlchemyStore obj's underlying member method code with example usage: obj.transition_model_version_stage(name, version, stage, archive_existing_versions) and returns: self