{"record":{"id":"bc059e51b0f37ee3","repo":"bytebase/bytebase","slug":"failed-to-get-semantic-types-setting","errorCode":null,"errorMessage":"failed to get semantic types setting","messagePattern":"failed to get semantic types setting","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/api/v1/query_result_masker.go","lineNumber":158,"sourceCode":"\t\treturn \"Partial mask\"\n\tcase *masker.MD5Masker:\n\t\treturn \"Hash (MD5)\"\n\tcase *masker.InnerOuterMasker:\n\t\t// Check the actual type by examining the mask result\n\t\treturn \"Inner/Outer mask\"\n\tdefault:\n\t\treturn \"Unknown\"\n\t}\n}\n\nfunc buildSemanticTypeToMaskerMap(ctx context.Context, stores *store.Store) (map[string]masker.Masker, error) {\n\tsemanticTypeToMasker := map[string]masker.Masker{\n\t\t\"bb.default\":         masker.NewDefaultFullMasker(),\n\t\t\"bb.default-partial\": masker.NewDefaultRangeMasker(),\n\t}\n\tsemanticTypesSetting, err := stores.GetSemanticTypesSetting(ctx, common.GetWorkspaceIDFromContext(ctx))\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"failed to get semantic types setting\")\n\t}\n\tfor _, semanticType := range semanticTypesSetting.GetTypes() {\n\t\tif semanticType.GetId() == \"bb.default\" || semanticType.GetId() == \"bb.default-partial\" {\n\t\t\t// Skip the built-in default semantic types.\n\t\t\tcontinue\n\t\t}\n\t\tm, err := getMaskerByMaskingAlgorithmAndLevel(semanticType.GetAlgorithm())\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\t// Only add semantic types that have actual masking configured (not NoneMasker)\n\t\tif _, isNoneMasker := m.(*masker.NoneMasker); !isNoneMasker {\n\t\t\tsemanticTypeToMasker[semanticType.GetId()] = m\n\t\t}\n\t}\n\n\treturn semanticTypeToMasker, nil\n}","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/bytebase/bytebase/blob/1870550677fe08f0d2a78c07acd27541464eb945/backend/api/v1/query_result_masker.go#L140-L176","documentation":"buildSemanticTypeToMaskerMap could not load the semantic types setting from the store while constructing the semantic-type-to-masker map used for column classification. The store error is wrapped as 'failed to get semantic types setting'.","triggerScenarios":"stores.GetSemanticTypesSetting(ctx, common.GetWorkspaceIDFromContext(ctx)) errors; this runs whenever spanTouchesMaskedColumns or getMaskersForQuerySpan needs the map, including inside queryRetry.","commonSituations":"Workspace ID absent from context causing lookup failure; metadata database unavailable; semantic types setting row deleted or corrupted; incomplete migrations.","solutions":["Ensure the workspace ID is set in the request context before calling query/export endpoints.","Check metadata DB health and re-run migrations if the setting is missing.","Re-create the semantic types setting if it was accidentally deleted.","Retry after transient metadata DB errors."],"exampleFix":"// before\nsemanticTypesSetting, err := stores.GetSemanticTypesSetting(ctx, common.GetWorkspaceIDFromContext(ctx))\nif err != nil {\n\treturn nil, errors.Wrap(err, \"failed to get semantic types setting\")\n}\n// after\nwsID := common.GetWorkspaceIDFromContext(ctx)\nif wsID == \"\" {\n\treturn nil, errors.New(\"workspace ID not in context\")\n}\nsemanticTypesSetting, err := stores.GetSemanticTypesSetting(ctx, wsID)\nif err != nil {\n\treturn nil, errors.Wrap(err, \"failed to get semantic types setting\")\n}","handlingStrategy":"try-catch","validationCode":"wsID := common.GetWorkspaceIDFromContext(ctx)\nif wsID == \"\" {\n\treturn errors.New(\"semantic types setting requires workspace context\")\n}","typeGuard":null,"tryCatchPattern":"maskers, err := buildSemanticTypeToMaskerMap(ctx, store)\nif err != nil {\n\t// retry once; then fail closed rather than returning unmasked data\n}","preventionTips":["Ensure middleware always injects workspace ID into context.","Do not delete or manually edit the semantic_types_setting row.","Run all pending migrations after upgrades.","Add health checks against the metadata DB in deployment probes."],"tags":["masking","database","config"],"backgroundTag":"database-query-failed","analyzedSha":"1870550677fe08f0d2a78c07acd27541464eb945","analyzedAt":"2026-09-06T21:16:13.665Z","contentChangedAt":"2026-09-06T21:16:13.665Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}