{"record":{"id":"d2e0684fcb5184c3","repo":"mlflow/mlflow","slug":"could-not-get-valid-view-type-corresponding-to-str-d2e068","errorCode":null,"errorMessage":"Could not get valid view type corresponding to string {view_type}. Valid view types are {list(cls._VIEW_TO_STRING.keys())}","messagePattern":"Could not get valid view type corresponding to string (.+?)\\. Valid view types are (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mlflow/entities/view_type.py","lineNumber":27,"sourceCode":"        ACTIVE_ONLY: \"active_only\",\n        DELETED_ONLY: \"deleted_only\",\n        ALL: \"all\",\n    }\n    _STRING_TO_VIEW = {value: key for key, value in _VIEW_TO_STRING.items()}\n\n    @classmethod\n    def from_string(cls, view_str: str) -> int:\n        if view_str not in cls._STRING_TO_VIEW:\n            raise Exception(\n                f\"Could not get valid view type corresponding to string {view_str}. \"\n                f\"Valid view types are {list(cls._STRING_TO_VIEW.keys())}\"\n            )\n        return cls._STRING_TO_VIEW[view_str]\n\n    @classmethod\n    def to_string(cls, view_type: int) -> str:\n        if view_type not in cls._VIEW_TO_STRING:\n            raise Exception(\n                f\"Could not get valid view type corresponding to string {view_type}. \"\n                f\"Valid view types are {list(cls._VIEW_TO_STRING.keys())}\"\n            )\n        return cls._VIEW_TO_STRING[view_type]\n\n    @classmethod\n    def to_proto(cls, view_type: int) -> service_pb2.ViewType:\n        if view_type == cls.ACTIVE_ONLY:\n            return service_pb2.ACTIVE_ONLY\n        elif view_type == cls.DELETED_ONLY:\n            return service_pb2.DELETED_ONLY\n        elif view_type == cls.ALL:\n            return service_pb2.ALL\n        raise ValueError(f\"Unexpected view_type: {view_type}\")\n\n    @classmethod\n    def from_proto(cls, proto_view_type: service_pb2.ViewType) -> int:\n        if proto_view_type == service_pb2.ACTIVE_ONLY:","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/mlflow/mlflow/blob/6a27f2decc0b76eb1b54af31849784addb357dbc/mlflow/entities/view_type.py#L9-L45","documentation":"ViewType.to_string() converts an integer view-type value back to its string form and raises when the integer is not one of the known view types. This is the inverse of from_string().","triggerScenarios":"Calling ViewType.to_string() with an arbitrary int (e.g. parsed from an untrusted request parameter) that is not ACTIVE_ONLY, DELETED_ONLY, or ALL's integer value.","commonSituations":"REST clients sending raw numeric view_type values outside the defined set; storing corrupted or stale view_type integers; tests passing 0/1/2 assumptions that don't match MLflow's values.","solutions":["Only pass values obtained from ViewType constants (ViewType.ALL etc.)","Validate the int against `ViewType._VIEW_TO_STRING.keys()` before calling","Sanitize API input: reject view_type ints outside the known set at the boundary"],"exampleFix":"// before\nViewType.to_string(int(request.args['view_type']))\n// after\nvt = int(request.args['view_type'])\nif vt in ViewType._VIEW_TO_STRING:\n    ViewType.to_string(vt)\nelse:\n    ViewType.to_string(ViewType.ACTIVE_ONLY)","handlingStrategy":"validation","validationCode":"from mlflow.entities import ViewType\ndef is_valid_view_int(v):\n    return v in ViewType._VIEW_TO_STRING","typeGuard":"def as_view_type(v):\n    return v if v in ViewType._VIEW_TO_STRING else None","tryCatchPattern":"try:\n    s = ViewType.to_string(view_type)\nexcept Exception:\n    s = ViewType.to_string(ViewType.ALL)","preventionTips":["Only derive view_type ints from ViewType constants","Reject numeric view_type params outside the known set","Don't assume 0/1/2 map to MLflow view types; check the enum"],"tags":["python","experiments","viewtype","invalid-input"],"backgroundTag":"invalid-enum-string","analyzedSha":"6a27f2decc0b76eb1b54af31849784addb357dbc","analyzedAt":"2026-08-29T20:54:51.419Z","schemaVersion":2},"datasetVersion":"2026-08-29T22:17:34.462Z"}