{"record":{"id":"d15fc5b64563ed51","repo":"infiniflow/ragflow","slug":"tenantmodel-id-model-id-cannot-be-used-as-model","errorCode":null,"errorMessage":"TenantModel id={model_id} cannot be used as {model_type_val} model.","messagePattern":"TenantModel id=(.+?) cannot be used as (.+?) model\\.","errorType":"exception","errorClass":"LookupError","httpStatus":null,"severity":"error","filePath":"api/db/joint_services/tenant_model_service.py","lineNumber":334,"sourceCode":"        if api_key_payload is not None:\n            model_config[\"api_key_payload\"] = api_key_payload\n\n        return model_config\n    else:\n        raise LookupError(f\"Model {model_name} not found for model {model_type_val}\")\n\n\ndef get_model_config_by_id(tenant_id: str, model_type: str | enum.Enum, model_id: str):\n    \"\"\"Get model config from tenant_model by its id (CharField PK).\"\"\"\n    model_type_val = model_type if isinstance(model_type, str) else model_type.value\n    model_type_bin = calculate_model_type(model_type_val)\n    exist, model_obj = TenantModelService.get_by_id(model_id)\n    if not exist:\n        raise LookupError(f\"TenantModel id={model_id} not found.\")\n    if model_obj.status == ActiveStatusEnum.INACTIVE.value:\n        raise LookupError(f\"TenantModel id={model_id} is disabled.\")\n    if model_obj.status == ActiveStatusEnum.UNSUPPORTED.value:\n        raise LookupError(f\"TenantModel id={model_id} cannot be used as {model_type_val} model.\")\n    if not (model_obj.model_type & model_type_bin):\n        raise LookupError(f\"TenantModel id={model_id} cannot be used as {model_type_val} model.\")\n\n    ok, provider_obj = TenantModelProviderService.get_by_id(model_obj.provider_id)\n    if not ok:\n        raise LookupError(f\"Provider id={model_obj.provider_id} not found for model id={model_id}.\")\n\n    # Validate that tenant_id owns the provider or is a joined tenant of the provider's owner.\n    if tenant_id != provider_obj.tenant_id:\n        joined_tenants = TenantService.get_joined_tenants_by_user_id(tenant_id)\n        joined_tenant_ids = [t[\"tenant_id\"] for t in joined_tenants]\n        if provider_obj.tenant_id not in joined_tenant_ids:\n            raise LookupError(f\"Tenant {tenant_id} has no access to provider owned by tenant {provider_obj.tenant_id}.\")\n\n    ok, instance_obj = TenantModelInstanceService.get_by_id(model_obj.instance_id)\n    if not ok:\n        raise LookupError(f\"Instance id={model_obj.instance_id} not found for model id={model_id}.\")\n","sourceCodeStart":316,"sourceCodeEnd":352,"githubUrl":"https://github.com/infiniflow/ragflow/blob/554fb1133ac3861732235ad9c377eb5e0a770665/api/db/joint_services/tenant_model_service.py#L316-L352","documentation":"LookupError raised by get_model_config_by_id when tenant_model.status equals ActiveStatusEnum.UNSUPPORTED. The row exists and is not disabled, but its status marks the model as unsupported (e.g. the provider type is not usable for this deployment). The message reuses the 'cannot be used as {model_type_val} model' wording also used for the model_type bitmask failure, so distinguish this raise (status-based, line 334) from the bitmask raise (line 336).","triggerScenarios":"Calling get_model_config_by_id for a model whose tenant_model.status == ActiveStatusEnum.UNSUPPORTED — e.g. a model registered under a provider the build cannot serve, or flipped to UNSUPPORTED during provider reconciliation/upgrade.","commonSituations":"Upgrading RAGFlow where a provider plugin is no longer bundled; models imported from another tenant/profile whose provider backend is absent; status written by a migration that flagged legacy providers.","solutions":["Check tenant_model.status for the id; if UNSUPPORTED, re-add the model under a supported provider and update references.","Verify the provider backend for that model type is available in the current deployment (image, COMPOSE_PROFILES, installed extras).","Delete the unsupported row to stop it appearing in selectors.","Migrate dependent datasets/assistants to a supported model id."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"exist, obj = TenantModelService.get_by_id(model_id)\nif exist and obj.status == ActiveStatusEnum.UNSUPPORTED.value:\n    raise RuntimeError(f\"Model {model_id} is unsupported in this deployment\")","typeGuard":null,"tryCatchPattern":"try:\n    config = get_model_config_by_id(tenant_id, model_type, model_id)\nexcept LookupError as e:\n    log.warning(\"unsupported model %s: %s\", model_id, e)\n    suggest_re registration_message(e)","preventionTips":["After upgrades, reconcile tenant_model status against providers actually bundled in the image.","Remove UNSUPPORTED rows so they stop appearing in selectors.","Verify provider backends exist (compose profiles, extras) before re-adding models."],"tags":["model-status","unsupported","tenant-model","ragflow"],"backgroundTag":null,"analyzedSha":"554fb1133ac3861732235ad9c377eb5e0a770665","analyzedAt":"2026-08-15T09:20:16.380Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}