def clone(
        self,
        name: str,
        api_key: str = None,  # type: ignore[assignment]
        clone_feature_states_async: bool = False,
    ) -> "Environment":
        """
        Creates a clone of the environment, related objects and returns the
        cloned object after saving it to the database.
        # NOTE: clone will not trigger create hooks
        """
        clone = deepcopy(self)
        clone.id = None
        clone.uuid = uuid.uuid4()
        clone.name = name
        clone.api_key = api_key if api_key else create_hash()
        clone.is_creating = True
        clone.save()

        from environments.tasks import clone_environment_feature_states

        kwargs = {"source_environment_id": self.id, "clone_environment_id": clone.id}

        if clone_feature_states_async:
            clone_environment_feature_states.delay(kwargs=kwargs)
        else:
            clone_environment_feature_states(**kwargs)

        return clone

        Creates a clone of the environment, related objects and returns the
        cloned object after saving it to the database.
        # NOTE: clone will not trigger create hooks
        
api/environments/models.py