{"record":{"id":"a3b91dae2b8df4d4","repo":"mlflow/mlflow","slug":"the-number-of-objectives-must-be-greater-than-0","errorCode":null,"errorMessage":"The number of objectives must be greater than 0.","messagePattern":"The number of objectives must be greater than 0\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mlflow/pyspark/optuna/study.py","lineNumber":204,"sourceCode":"    def __init__(\n        self,\n        study_name: str,\n        storage: MlflowStorage,\n        sampler: samplers.BaseSampler | None = None,\n        pruner: pruners.BasePruner | None = None,\n        mlflow_tracking_uri: str | None = None,\n        direction: str | StudyDirection | None = None,\n        directions: Sequence[str | StudyDirection] | None = None,\n    ):\n        if direction is not None and directions is not None:\n            raise ValueError(\"Specify only one of `direction` and `directions`.\")\n        if isinstance(directions, str):\n            raise ValueError(\n                \"`directions` must be a sequence (e.g. list or tuple) of direction values, \"\n                \"not a string. For single-objective optimization, use `direction=` instead.\"\n            )\n        if directions is not None and len(directions) == 0:\n            raise ValueError(\"The number of objectives must be greater than 0.\")\n        self.study_name = study_name\n        self._storage = storages.get_storage(storage)\n        self.sampler = sampler or samplers.TPESampler()\n        self.pruner = pruner if pruner is not None else pruners.MedianPruner()\n\n        self.spark = SparkSession.active()\n\n        # check whether the SparkConnect mode\n        self._is_spark_connect_mode = is_spark_connect_mode()\n        self._mlflow_tracking_env = mlflow_tracking_uri or mlflow.get_tracking_uri()\n        mlflow.set_tracking_uri(self._mlflow_tracking_env)\n        self.mlflow_client = MlflowClient()\n\n        if not isinstance(self._storage, MlflowStorage):\n            raise ValueError(\n                f\"MlflowSparkStudy only works with `MlflowStorage`. But get {type(self._storage)}.\"\n            )\n","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/mlflow/mlflow/blob/6a27f2decc0b76eb1b54af31849784addb357dbc/mlflow/pyspark/optuna/study.py#L186-L222","documentation":"A multi-objective study must declare at least one direction. MlflowSparkStudy raises this ValueError when directions is provided as an empty sequence, because an empty objectives list cannot be optimized.","triggerScenarios":"Calling MlflowSparkStudy(directions=[]) or passing an empty config list to directions.","commonSituations":"Building the directions list dynamically from config/CLI where defaults left it empty; an upstream filter removed all directions.","solutions":["Provide at least one direction, e.g. directions=[\"minimize\"].","Use direction= for a single objective.","Validate the directions list length > 0 before constructing the study.","Fix the config source that produced an empty list."],"exampleFix":"# before\nstudy = MlflowSparkStudy(directions=[])\n# after\nstudy = MlflowSparkStudy(direction=[\"minimize\"][0] if n_obj == 1 else None, directions=[\"minimize\"] if n_obj > 1 else None)","handlingStrategy":"validation","validationCode":"if directions is not None and len(directions) == 0:\n    raise ValueError(\"directions must contain at least one direction\")","typeGuard":null,"tryCatchPattern":"try:\n    study = MlflowSparkStudy(directions=obj_dirs)\nexcept ValueError as e:\n    if \"greater than 0\" in str(e):\n        obj_dirs = [\"minimize\"]\n        study = MlflowSparkStudy(direction=obj_dirs[0])","preventionTips":["Validate objectives config has >= 1 entry before study creation","Provide a sane default direction for single-objective runs","Guard dynamic directions-list builders against empty results"],"tags":["optuna","pyspark","validation","empty-list"],"backgroundTag":"invalid-parameter","analyzedSha":"6a27f2decc0b76eb1b54af31849784addb357dbc","analyzedAt":"2026-08-29T20:54:51.419Z","schemaVersion":2},"datasetVersion":"2026-08-29T22:17:34.462Z"}