def _export_features_for_environment(
    feature_export: FeatureExport, tag_ids: Optional[list[int]]
) -> None:
    """
    Caller for the export_features_for_environment to handle fails.
    """
    additional_filters = Q(
        identity__isnull=True,
        feature_segment__isnull=True,
        feature_state_value__isnull=False,
        feature__is_archived=False,
    )

    if tag_ids:
        additional_filters &= Q(feature__tags__in=tag_ids)

    environment = feature_export.environment
    feature_states = get_environment_flags_list(
        environment=environment,
        additional_filters=additional_filters,
    )

    payload = []
    for feature_state in feature_states:
        multivariate = [
            {
                "percentage_allocation": mv_fsv.percentage_allocation,
                "default_percentage_allocation": mv_fsv.multivariate_feature_option.default_percentage_allocation,
                "value": mv_fsv.multivariate_feature_option.value,
                "type": mv_fsv.multivariate_feature_option.type,
            }
            for mv_fsv in feature_state.multivariate_feature_state_values.select_related(
                "multivariate_feature_option"
            ).all()
        ]

        payload.append(
            {
                "name": feature_state.feature.name,
                "default_enabled": feature_state.feature.default_enabled,
                "is_server_key_only": feature_state.feature.is_server_key_only,
                "initial_value": feature_state.feature.initial_value,
                "value": feature_state.feature_state_value.value,
                "type": feature_state.feature_state_value.type,
                "enabled": feature_state.enabled,
                "multivariate": multivariate,
            }
        )

    feature_export.status = SUCCESS
    feature_export.data = json.dumps(payload)
    feature_export.save()

    Caller for the export_features_for_environment to handle fails.
    
api/features/import_export/tasks.py