Bug Description
After updating an embedding model configuration (api_key / base_url) via the RAGFlow UI, already-queued document parsing tasks fail with:
openai.OpenAIError: Missing credentials. Please pass an `api_key`, `workload_identity`, `admin_api_key`, or set the `OPENAI_API_KEY` or `OPENAI_ADMIN_KEY` environment variable.
The root cause is that the task caches a stale tenant_embd_id pointing to an old tenant_model_instance record whose api_key is empty.
Reproduce
- Add an OpenAI-API-Compatible embedding model (e.g.
harrier-oss-v1-0.6b) with api_key and base_url
- Upload a document and start parsing — task is queued with
tenant_embd_id pointing to the current tenant_model_instance record
- Update the embedding model config in the UI (change api_key / base_url) — RAGFlow creates a new
tenant_model_instance record and updates tenant.tenant_embd_id to point to it; the old record is left behind with api_key=""
- The queued task from step 2 executes — it uses the cached old
tenant_embd_id, looks up the old tenant_model_instance record, gets api_key="", passes it to OpenAI(api_key=""), and crashes
Expected Behavior
Already-queued tasks should either:
- Re-resolve the model config from the tenant's current
tenant_embd_id at execution time, OR
- Fall back to the global
embd_id when the cached tenant_embd_id yields an empty api_key
Actual Behavior
task_handler.py only falls back when get_model_config_by_id raises LookupError (record not found). But the old record still exists (just with an empty api_key), so no LookupError is raised, and the empty api_key is passed directly to the OpenAI client constructor.
# task_handler.py:355-366
if ctx.tenant_embd_id:
try:
embd_model_config = get_model_config_by_id(task_tenant_id, LLMType.EMBEDDING, ctx.tenant_embd_id)
except LookupError:
embd_model_config = resolve_model_config(task_tenant_id, LLMType.EMBEDDING, task_embedding_id)
The except LookupError only catches "record not found". An empty api_key is not detected — it flows through to model_instance() → EmbeddingModel[...](api_key="", ...) → OpenAI(api_key="") → crash.
Environment
- RAGFlow image:
infiniflow/ragflow:latest
- Version:
v0.26.4-831-gf532f27f1 (0d5486a, v0.14.1~75 full)
- Deployment: Docker Compose (CPU profile)
- Model: OpenAI-API-Compatible embedding (
harrier-oss-v1-0.6b)
Workaround
Manually update the old tenant_model_instance record to set the correct api_key:
UPDATE tenant_model_instance SET api_key='sk-embed' WHERE id='<old_instance_id>';
Suggested Fix
In get_model_config_by_id (or task_handler._bind_embedding_model), add a validation that api_key is non-empty after lookup. If empty, fall back to resolve_model_config or raise a more descriptive error instead of letting an empty string propagate to the OpenAI SDK.
Bug Description
After updating an embedding model configuration (api_key / base_url) via the RAGFlow UI, already-queued document parsing tasks fail with:
The root cause is that the task caches a stale
tenant_embd_idpointing to an oldtenant_model_instancerecord whoseapi_keyis empty.Reproduce
harrier-oss-v1-0.6b) with api_key and base_urltenant_embd_idpointing to the currenttenant_model_instancerecordtenant_model_instancerecord and updatestenant.tenant_embd_idto point to it; the old record is left behind withapi_key=""tenant_embd_id, looks up the oldtenant_model_instancerecord, getsapi_key="", passes it toOpenAI(api_key=""), and crashesExpected Behavior
Already-queued tasks should either:
tenant_embd_idat execution time, ORembd_idwhen the cachedtenant_embd_idyields an empty api_keyActual Behavior
task_handler.pyonly falls back whenget_model_config_by_idraisesLookupError(record not found). But the old record still exists (just with an emptyapi_key), so noLookupErroris raised, and the emptyapi_keyis passed directly to the OpenAI client constructor.The
except LookupErroronly catches "record not found". An emptyapi_keyis not detected — it flows through tomodel_instance()→EmbeddingModel[...](api_key="", ...)→OpenAI(api_key="")→ crash.Environment
infiniflow/ragflow:latestv0.26.4-831-gf532f27f1(0d5486a, v0.14.1~75 full)harrier-oss-v1-0.6b)Workaround
Manually update the old
tenant_model_instancerecord to set the correctapi_key:Suggested Fix
In
get_model_config_by_id(ortask_handler._bind_embedding_model), add a validation thatapi_keyis non-empty after lookup. If empty, fall back toresolve_model_configor raise a more descriptive error instead of letting an empty string propagate to the OpenAI SDK.