{"record":{"id":"5f541a9cba445e90","repo":"apache/beam","slug":"unsupported-serialization-type","errorCode":null,"errorMessage":"Unsupported serialization type.","messagePattern":"Unsupported serialization type\\.","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/ml/inference/sklearn_inference.py","lineNumber":69,"sourceCode":"class ModelFileType(enum.Enum):\n  \"\"\"Defines how a model file is serialized. Options are pickle or joblib.\"\"\"\n  PICKLE = 1\n  JOBLIB = 2\n\n\ndef _load_model(model_uri, file_type):\n  file = FileSystems.open(model_uri, 'rb')\n  if file_type == ModelFileType.PICKLE:\n    return pickle.load(file)\n  elif file_type == ModelFileType.JOBLIB:\n    if not joblib:\n      raise ImportError(\n          'Could not import joblib in this execution environment. '\n          'For help with managing dependencies on Python workers.'\n          'see https://beam.apache.org/documentation/sdks/python-pipeline-dependencies/'  # pylint: disable=line-too-long\n      )\n    return joblib.load(file)\n  raise AssertionError('Unsupported serialization type.')\n\n\ndef _default_numpy_inference_fn(\n    model: BaseEstimator,\n    batch: Sequence[numpy.ndarray],\n    inference_args: Optional[dict[str, Any]] = None) -> Any:\n  inference_args = {} if not inference_args else inference_args\n  # vectorize data for better performance\n  vectorized_batch = numpy.stack(batch, axis=0)\n  return model.predict(vectorized_batch, **inference_args)\n\n\nclass SklearnModelHandlerNumpy(ModelHandler[numpy.ndarray,\n                                            PredictionResult,\n                                            BaseEstimator]):\n  def __init__(\n      self,\n      model_uri: str,","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/ml/inference/sklearn_inference.py#L51-L87","documentation":"Raised in sklearn_inference._load_model as an AssertionError when the provided file_type is neither PICKLE nor JOBLIB. It is the terminal fall-through guard after the ModelFileType branches, meaning an unsupported serialization type reached the loader.","triggerScenarios":"Calling SklearnModelHandler (or _load_model) with a model_file_type value outside the ModelFileType enum's PICKLE/JOBLIB members, or constructing the enum with an arbitrary value.","commonSituations":"Passing a raw string instead of a ModelFileType enum member; an enum version mismatch where a new member exists in a newer Beam version than the worker runs; typo-ed enum construction via ModelFileType('pickle') with wrong case.","solutions":["Pass model_file_type as ModelFileType.PICKLE or ModelFileType.JOBLIB explicitly","Verify the ModelFileType enum members available in your installed Beam version","Upgrade apache-beam on workers if the serialization type was added in a newer release"],"exampleFix":"// before\nhandler = SklearnModelHandler(model_uri=uri, model_file_type='joblib')\n// after\nhandler = SklearnModelHandler(model_uri=uri, model_file_type=ModelFileType.JOBLIB)","handlingStrategy":"validation","validationCode":"from apache_beam.ml.inference.sklearn_inference import ModelFileType\nassert model_file_type in (ModelFileType.PICKLE, ModelFileType.JOBLIB), f'Unsupported type: {model_file_type}'","typeGuard":"def is_supported_model_file_type(t) -> bool:\n    return t in (ModelFileType.PICKLE, ModelFileType.JOBLIB)","tryCatchPattern":"try:\n    model = handler.load_model()\nexcept AssertionError as e:\n    if 'Unsupported serialization type' in str(e):\n        handler.model_file_type = ModelFileType.PICKLE\n        model = handler.load_model()\n    else:\n        raise","preventionTips":["Always reference ModelFileType enum members, never raw strings","Check enum members against your installed apache-beam version","Validate handler construction in unit tests before pipeline launch"],"tags":["python","apache-beam","sklearn","enum","serialization"],"backgroundTag":"unsupported-enum-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}