{"record":{"id":"c34e16773912ff3c","repo":"Tencent/WeKnora","slug":"workspace-id-not-found-in-context-c34e16","errorCode":null,"errorMessage":"workspace ID not found in context","messagePattern":"workspace ID not found in context","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/service/web_search.go","lineNumber":97,"sourceCode":"\t// Apply blacklist filtering\n\tresults = s.filterBlacklist(results, config.Blacklist)\n\n\treturn results, nil\n}\n\n// resolveProvider resolves a WebSearchProvider instance from either:\n// 1. A provider entity ID (new path) — loads from DB, creates via registry\n// 2. The deprecated config.Provider field (backward compatibility) — creates with empty params\nfunc (s *WebSearchService) resolveProvider(\n\tctx context.Context,\n\tproviderID string,\n\tcfg *types.WebSearchConfig,\n) (interfaces.WebSearchProvider, error) {\n\t// New path: load provider entity from DB\n\tif providerID != \"\" {\n\t\ttenantID, ok := types.TenantIDFromContext(ctx)\n\t\tif !ok {\n\t\t\treturn nil, fmt.Errorf(\"workspace ID not found in context\")\n\t\t}\n\n\t\tentity, err := s.providerRepo.GetByID(ctx, tenantID, providerID)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to load web search provider %s: %w\", providerID, err)\n\t\t}\n\t\tif entity == nil {\n\t\t\treturn nil, fmt.Errorf(\"web search provider not found: %s\", providerID)\n\t\t}\n\n\t\tparams := mergeProxyFromWebSearchConfig(entity.Parameters, cfg)\n\t\tprovider, err := s.registry.CreateProvider(string(entity.Provider), params)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to create provider %s (%s): %w\", entity.Name, entity.Provider, err)\n\t\t}\n\t\treturn provider, nil\n\t}\n","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/web_search.go#L79-L115","documentation":"resolveProvider cannot find a tenant/workspace ID in the request context when loading a provider entity by ID. Provider entities are tenant-scoped, so the DB lookup is impossible without it — usually missing auth middleware or context propagation.","triggerScenarios":"Thrown at internal/application/service/web_search.go:97 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure tenant-auth middleware runs before web search handling","Propagate the tenant ID into the context on internal call paths","Only use the providerID path from tenant-scoped requests"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}