{"record":{"id":"ff03de2c0bc7701c","repo":"Tencent/WeKnora","slug":"knowledge-base-id-is-required","errorCode":null,"errorMessage":"knowledge_base_id is required","messagePattern":"knowledge_base_id is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/application/service/wiki_page.go","lineNumber":78,"sourceCode":"\treturn &wikiPageService{\n\t\trepo:            repo,\n\t\tchunkRepo:       chunkRepo,\n\t\tkbService:       kbService,\n\t\ttaskPendingRepo: taskPendingRepo,\n\t\tredisClient:     redisClient,\n\t}\n}\n\n// CreatePage creates a new wiki page\nfunc (s *wikiPageService) CreatePage(ctx context.Context, page *types.WikiPage) (*types.WikiPage, error) {\n\tif page.ID == \"\" {\n\t\tpage.ID = uuid.New().String()\n\t}\n\tif page.Slug == \"\" {\n\t\treturn nil, errors.New(\"wiki page slug is required\")\n\t}\n\tif page.KnowledgeBaseID == \"\" {\n\t\treturn nil, errors.New(\"knowledge_base_id is required\")\n\t}\n\tif page.Status == \"\" {\n\t\tpage.Status = types.WikiPageStatusPublished\n\t}\n\tif page.Version == 0 {\n\t\tpage.Version = 1\n\t}\n\tpage.LastEditSource = types.WikiEditSourceFromContext(ctx)\n\tpage.LastEditorID, _ = types.UserIDFromContext(ctx)\n\tstripWikiPageInlineChunkCitations(page)\n\n\t// Parse outbound links from content\n\tpage.OutLinks = s.parseOutLinks(page.Content)\n\tif err := s.applyFolderToPage(ctx, page); err != nil {\n\t\treturn nil, err\n\t}\n\tnormalizeWikiHierarchy(page)\n","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/wiki_page.go#L60-L96","documentation":"CreatePage requires the page to reference a knowledge base; when page.KnowledgeBaseID is empty the service returns this error. Without the KB association the page cannot be scoped, listed, or have its slug uniqueness enforced within the right namespace.","triggerScenarios":"Calling CreatePage with page.KnowledgeBaseID == \"\" — e.g. the request did not include the KB id, or a route param failed to bind into the WikiPage struct.","commonSituations":"Client omits knowledge_base_id in the create payload; endpoint refactor renamed the field so binding now leaves it empty; scripts creating pages across KBs forgetting the association.","solutions":["Populate page.KnowledgeBaseID from the request/route context before calling CreatePage.","Validate knowledge_base_id is present at the handler boundary and return 400 otherwise.","Verify the JSON tag/field name used by request binding matches what clients send."],"exampleFix":"// before\npage := &types.WikiPage{Slug: slug, Title: req.Title}\n// after\npage := &types.WikiPage{Slug: slug, Title: req.Title, KnowledgeBaseID: kbIDFromRequest}","handlingStrategy":"validation","validationCode":"if strings.TrimSpace(page.KnowledgeBaseID) == \"\" {\n    return httpError(400, \"knowledge_base_id is required\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Populate KnowledgeBaseID from route context in a shared handler helper.","Mark knowledge_base_id as binding:\"required\" on request structs.","Keep JSON tag names in sync with client payloads after refactors."],"tags":["validation","wiki","missing-field"],"backgroundTag":"missing-required-argument","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}