{"record":{"id":"71bb8623b361ebf9","repo":"apache/beam","slug":"unexpected-value-for-minimum-importance-argument-r","errorCode":null,"errorMessage":"Unexpected value for minimum_importance argument: %r","messagePattern":"Unexpected value for minimum_importance argument: %r","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/runners/dataflow/internal/apiclient.py","lineNumber":1073,"sourceCode":"      request.end_time = end_time\n    if minimum_importance is not None:\n      if minimum_importance == 'JOB_MESSAGE_DEBUG':\n        request.minimum_importance = (\n            dataflow.JobMessageImportance.JOB_MESSAGE_DEBUG)\n      elif minimum_importance == 'JOB_MESSAGE_DETAILED':\n        request.minimum_importance = (\n            dataflow.JobMessageImportance.JOB_MESSAGE_DETAILED)\n      elif minimum_importance == 'JOB_MESSAGE_BASIC':\n        request.minimum_importance = (\n            dataflow.JobMessageImportance.JOB_MESSAGE_BASIC)\n      elif minimum_importance == 'JOB_MESSAGE_WARNING':\n        request.minimum_importance = (\n            dataflow.JobMessageImportance.JOB_MESSAGE_WARNING)\n      elif minimum_importance == 'JOB_MESSAGE_ERROR':\n        request.minimum_importance = (\n            dataflow.JobMessageImportance.JOB_MESSAGE_ERROR)\n      else:\n        raise RuntimeError(\n            'Unexpected value for minimum_importance argument: %r' %\n            minimum_importance)\n    response = self._messages_client.list_job_messages(request=request)\n    return response.job_messages, response.next_page_token\n\n  def job_id_for_name(self, job_name):\n    token = None\n    while True:\n      request = dataflow.ListJobsRequest(\n          project_id=self.google_cloud_options.project,\n          location=self.google_cloud_options.region,\n          page_token=token)\n      response = self._jobs_client.list_jobs(request)\n      for job in response:\n        if (job.name == job_name and\n            job.current_state in [dataflow.JobState.JOB_STATE_RUNNING,\n                                  dataflow.JobState.JOB_STATE_DRAINING]):\n          return job.id","sourceCodeStart":1055,"sourceCodeEnd":1091,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/runners/dataflow/internal/apiclient.py#L1055-L1091","documentation":"RuntimeError from DataflowApplicationClient.list_messages when minimum_importance is provided but does not match any recognized JobMessageImportance enum value. Only JOB_MESSAGE_WARNING and JOB_MESSAGE_ERROR (and the accepted defaults like JOB_MESSAGE_BASIC/DETAILED handled earlier) are mapped onto the API request. Any other string fails before the API call.","triggerScenarios":"Calling list_messages(job_id, minimum_importance=<value>) with a misspelled or non-enum string such as 'WARNING', 'error', or an arbitrary object, where the if/elif chain doesn't match.","commonSituations":"Typo'd importance level in monitoring scripts; passing a lowercase variant; using an enum constant from a different library.","solutions":["Use an exact Dataflow enum string, e.g. 'JOB_MESSAGE_WARNING' or 'JOB_MESSAGE_ERROR'.","Use dataflow.JobMessageImportance enum members from the generated client rather than raw strings.","Print accepted values and compare before calling: check the if/elif mapping in list_messages."],"exampleFix":"// before\nclient.list_messages(job_id, minimum_importance='warning')\n// after\nclient.list_messages(job_id, minimum_importance='JOB_MESSAGE_WARNING')","handlingStrategy":"validation","validationCode":"VALID = {'JOB_MESSAGE_WARNING', 'JOB_MESSAGE_ERROR'}\nif minimum_importance not in VALID:\n    raise ValueError(f'minimum_importance must be one of {sorted(VALID)}, got {minimum_importance!r}')","typeGuard":"def is_valid_importance(v) -> bool:\n    return isinstance(v, str) and v in {'JOB_MESSAGE_WARNING', 'JOB_MESSAGE_ERROR'}","tryCatchPattern":"try:\n    msgs, token = client.list_messages(job_id, minimum_importance=level)\nexcept RuntimeError as e:\n    if 'minimum_importance' in str(e):\n        level = 'JOB_MESSAGE_ERROR'\n        msgs, token = client.list_messages(job_id, minimum_importance=level)","preventionTips":["Copy enum values directly from the generated dataflow client, never by hand.","Write the importance level as a module-level constant.","Add a unit test covering the exact string values."],"tags":["python","apache-beam","dataflow","invalid-argument"],"backgroundTag":"invalid-enum-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}