{"record":{"id":"49b477001ab18c43","repo":"mlflow/mlflow","slug":"could-not-get-string-corresponding-to-run-status","errorCode":null,"errorMessage":"Could not get string corresponding to run status {status}. Valid run statuses: {list(RunStatus._STATUS_TO_STRING.keys())}","messagePattern":"Could not get string corresponding to run status (.+?)\\. Valid run statuses: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mlflow/entities/run_status.py","lineNumber":29,"sourceCode":"    KILLED: int = ProtoRunStatus.Value(\"KILLED\")\n\n    _STRING_TO_STATUS: dict[str, int] = {k: ProtoRunStatus.Value(k) for k in ProtoRunStatus.keys()}\n    _STATUS_TO_STRING = {value: key for key, value in _STRING_TO_STATUS.items()}\n    _TERMINATED_STATUSES = {FINISHED, FAILED, KILLED}\n\n    @staticmethod\n    def from_string(status_str: str) -> int:\n        if status_str not in RunStatus._STRING_TO_STATUS:\n            raise Exception(\n                f\"Could not get run status corresponding to string {status_str}. Valid run \"\n                f\"status strings: {list(RunStatus._STRING_TO_STATUS.keys())}\"\n            )\n        return RunStatus._STRING_TO_STATUS[status_str]\n\n    @staticmethod\n    def to_string(status: int) -> str:\n        if status not in RunStatus._STATUS_TO_STRING:\n            raise Exception(\n                f\"Could not get string corresponding to run status {status}. Valid run \"\n                f\"statuses: {list(RunStatus._STATUS_TO_STRING.keys())}\"\n            )\n        return RunStatus._STATUS_TO_STRING[status]\n\n    @staticmethod\n    def is_terminated(status: int) -> bool:\n        return status in RunStatus._TERMINATED_STATUSES\n\n    @staticmethod\n    def all_status() -> list[int]:\n        return list(RunStatus._STATUS_TO_STRING.keys())\n","sourceCodeStart":11,"sourceCodeEnd":42,"githubUrl":"https://github.com/mlflow/mlflow/blob/6a27f2decc0b76eb1b54af31849784addb357dbc/mlflow/entities/run_status.py#L11-L42","documentation":"RunStatus.to_string converts an integer status enum value back to its string name and raises when the integer is not a known RunStatus value. This guards against corrupt or out-of-range status integers.","triggerScenarios":"Calling RunStatus.to_string with an int not in the enum (e.g. 0, 99), often an uninitialized value or a status from a foreign system.","commonSituations":"Reading status ints from external databases/APIs that use different numeric codes; arithmetic on status values; passing None or a string where an int is expected.","solutions":["Only pass RunStatus enum members: RunStatus.to_string(RunStatus.FINISHED).","Check membership first: if status in RunStatus._STATUS_TO_STRING.","Map foreign codes to RunStatus values before conversion."],"exampleFix":"// before\nname = RunStatus.to_string(status_int)  # raises for unknown ints\n// after\nname = RunStatus.to_string(status_int) if status_int in RunStatus._STATUS_TO_STRING else 'UNKNOWN'","handlingStrategy":"validation","validationCode":"from mlflow.entities import RunStatus\nif status not in RunStatus._STATUS_TO_STRING:\n    status = RunStatus.FAILED  # or translate foreign numeric codes first","typeGuard":"from mlflow.entities import RunStatus\ndef is_run_status(v) -> bool:\n    return isinstance(v, int) and v in RunStatus._STATUS_TO_STRING","tryCatchPattern":"try:\n    name = RunStatus.to_string(status)\nexcept Exception:\n    name = 'UNKNOWN'  # or translate the foreign code, then retry","preventionTips":["Only pass RunStatus enum members, never raw ints from other systems.","Translate foreign numeric status codes before conversion.","Guard with `status in RunStatus._STATUS_TO_STRING` for untrusted input."],"tags":["mlflow","run-status","enum-conversion"],"backgroundTag":"invalid-enum-value","analyzedSha":"6a27f2decc0b76eb1b54af31849784addb357dbc","analyzedAt":"2026-08-29T20:54:51.419Z","schemaVersion":2},"datasetVersion":"2026-08-29T22:17:34.462Z"}