{"record":{"id":"12a8019fd1b3bd71","repo":"docling-project/docling","slug":"expected-onnxruntimeobjectdetectionengineoptions","errorCode":null,"errorMessage":"Expected OnnxRuntimeObjectDetectionEngineOptions, got {type(options)}","messagePattern":"Expected OnnxRuntimeObjectDetectionEngineOptions, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"docling/models/inference_engines/object_detection/factory.py","lineNumber":58,"sourceCode":"        artifacts_path: Optional path to local model artifacts root\n\n    Returns:\n        Initialized engine instance (call .initialize() before use)\n    \"\"\"\n    model_config: Optional[EngineModelConfig] = None\n    if model_spec is not None:\n        model_config = model_spec.get_engine_config(options.engine_type)\n\n    if options.engine_type == ObjectDetectionEngineType.ONNXRUNTIME:\n        from docling.datamodel.object_detection_engine_options import (\n            OnnxRuntimeObjectDetectionEngineOptions,\n        )\n        from docling.models.inference_engines.object_detection.onnxruntime_engine import (\n            OnnxRuntimeObjectDetectionEngine,\n        )\n\n        if not isinstance(options, OnnxRuntimeObjectDetectionEngineOptions):\n            raise ValueError(\n                f\"Expected OnnxRuntimeObjectDetectionEngineOptions, got {type(options)}\"\n            )\n\n        return OnnxRuntimeObjectDetectionEngine(\n            options=options,\n            model_config=model_config,\n            artifacts_path=artifacts_path,\n            accelerator_options=accelerator_options,\n        )\n\n    elif options.engine_type == ObjectDetectionEngineType.TRANSFORMERS:\n        from docling.datamodel.object_detection_engine_options import (\n            TransformersObjectDetectionEngineOptions,\n        )\n        from docling.models.inference_engines.object_detection.transformers_engine import (\n            TransformersObjectDetectionEngine,\n        )\n","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/docling-project/docling/blob/61d76f1ff3f8428065465889f7b4577da7df704c/docling/models/inference_engines/object_detection/factory.py#L40-L76","documentation":"The object-detection engine factory dispatches on options.engine_type. When engine_type is ONNXRUNTIME but the options object is not an OnnxRuntimeObjectDetectionEngineOptions instance, it raises ValueError. This catches inconsistent configuration where the enum tag and the options payload disagree.","triggerScenarios":"Setting options.engine_type = ObjectDetectionEngineType.ONNXRUNTIME on an options object of a different class (e.g. ApiKserveV2ObjectDetectionEngineOptions or a hand-built subclass), then calling the factory create function.","commonSituations":"Copy-pasting options classes and tweaking engine_type instead of using the right class; deserializing options from YAML/JSON into the wrong concrete type; mutating a shared options instance across pipelines.","solutions":["Use OnnxRuntimeObjectDetectionEngineOptions as the options object — its default engine_type already selects ONNXRUNTIME.","If loading options from config files, deserialize into the concrete class matching the engine_type field.","Never assign engine_type on an options instance of a different engine family."],"exampleFix":"# before\nopts = ApiKserveV2ObjectDetectionEngineOptions(url=url)\nopts.engine_type = ObjectDetectionEngineType.ONNXRUNTIME\nengine = create_object_detection_engine(options=opts)\n\n# after\nfrom docling.datamodel.object_detection_engine_options import OnnxRuntimeObjectDetectionEngineOptions\nopts = OnnxRuntimeObjectDetectionEngineOptions()\nengine = create_object_detection_engine(options=opts)","handlingStrategy":"type-guard","validationCode":"from docling.datamodel.object_detection_engine_options import OnnxRuntimeObjectDetectionEngineOptions\nassert isinstance(opts, OnnxRuntimeObjectDetectionEngineOptions), type(opts)","typeGuard":"def is_onnx_opts(o: object) -> TypeGuard[OnnxRuntimeObjectDetectionEngineOptions]:\n    return isinstance(o, OnnxRuntimeObjectDetectionEngineOptions)","tryCatchPattern":"try:\n    engine = create_object_detection_engine(options=opts)\nexcept ValueError as e:\n    raise ConfigurationError(str(e)) from e  # surface config mismatch at startup","preventionTips":["Never reassign engine_type across option classes; construct the matching class.","Validate options type right after deserializing config files.","Keep one options class per engine family in your config schema."],"tags":["configuration","factory","type-mismatch","object-detection"],"backgroundTag":null,"analyzedSha":"61d76f1ff3f8428065465889f7b4577da7df704c","analyzedAt":"2026-08-14T23:53:18.727Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}