# Buggy code
def _create_default_experiment(self, session):
    """
    MLflow UI and client code expects a default experiment with ID 0.
    This method uses SQL insert statement to create the default experiment as a hack, since
    experiment table uses 'experiment_id' column is a PK and is also set to auto increment.
    MySQL and other implementation do not allow value '0' for such cases.

    ToDo: Identify a less hacky mechanism to create default experiment 0
    """
    table = SqlExperiment.__tablename__
    default_experiment = {
        SqlExperiment.experiment_id.name: int(SqlAlchemyStore.DEFAULT_EXPERIMENT_ID),
        SqlExperiment.name.name: Experiment.DEFAULT_EXPERIMENT_NAME,
        SqlExperiment.artifact_location.name: str(self._get_artifact_location(0)),
        SqlExperiment.lifecycle_stage.name: LifecycleStage.ACTIVE,
    }

    def decorate(s):
        if isinstance(s, str):
            return "'{}'".format(s)
        else:
            return "{}".format(s)

    # Get a list of keys to ensure we have a deterministic ordering
    columns = list(default_experiment.keys())
    values = ", ".join([decorate(default_experiment.get(c)) for c in columns])

    try:
        self._set_no_auto_for_zero_values(session)
        session.execute(
            "INSERT INTO {} ({}) VALUES ({});".format(table, ", ".join(columns), values)
        )
    finally:
        self._unset_no_auto_for_zero_values(session)


# Traceback (pyodbc.IntegrityError)
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1244, in _execute_context
cursor, statement, parameters, context
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/default.py", line 552, in do_execute
cursor.execute(statement, parameters)
pyodbc.IntegrityError: ('23000', "[23000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Cannot insert explicit value for identity column in table 'experiments' when IDENTITY_INSERT is set to OFF. (544) (SQLExecDirectW)")

# Fixed code
def _create_default_experiment(self, session):
    """
    MLflow UI and client code expects a default experiment with ID 0.
    This method uses SQL insert statement to create the default experiment as a hack, since
    experiment table uses 'experiment_id' column is a PK and is also set to auto increment.
    MySQL and other implementation do not allow value '0' for such cases.

    ToDo: Identify a less hacky mechanism to create default experiment 0
    """
    table = SqlExperiment.__tablename__
    default_experiment = {
        SqlExperiment.experiment_id.name: int(SqlAlchemyStore.DEFAULT_EXPERIMENT_ID),
        SqlExperiment.name.name: Experiment.DEFAULT_EXPERIMENT_NAME,
        SqlExperiment.artifact_location.name: str(self._get_artifact_location(0)),
        SqlExperiment.lifecycle_stage.name: LifecycleStage.ACTIVE,
    }

    def decorate(s):
        if isinstance(s, str):
            return "'{}'".format(s)
        else:
            return "{}".format(s)

    # Get a list of keys to ensure we have a deterministic ordering
    columns = list(default_experiment.keys())
    values = ", ".join([decorate(default_experiment.get(c)) for c in columns])

    try:
        self._set_zero_value_insertion_for_autoincrement_column(session)
        session.execute(
            "INSERT INTO {} ({}) VALUES ({});".format(table, ", ".join(columns), values)
        )
    finally:
        self._unset_zero_value_insertion_for_autoincrement_column(session)