{"record":{"id":"86c0ef0fae038d67","repo":"temporalio/temporal","slug":"searchprecision-requires-a-starttime-or-closetime","errorCode":null,"errorMessage":"SearchPrecision requires a StartTime or CloseTime","messagePattern":"SearchPrecision requires a StartTime or CloseTime","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/archiver/s3store/query_parser.go","lineNumber":79,"sourceCode":"\tparsedQuery := &parsedQuery{}\n\tif err := p.convertWhereExpr(whereExpr, parsedQuery); err != nil {\n\t\treturn nil, err\n\t}\n\tif parsedQuery.workflowID == nil && parsedQuery.workflowType == nil {\n\t\treturn nil, errors.New(\"WorkflowId or WorkflowType is required in query\")\n\t}\n\tif parsedQuery.workflowID != nil && parsedQuery.workflowType != nil {\n\t\treturn nil, errors.New(\"only one of WorkflowId or WorkflowType can be specified in a query\")\n\t}\n\tif parsedQuery.closeTime != nil && parsedQuery.startTime != nil {\n\t\treturn nil, errors.New(\"only one of StartTime or CloseTime can be specified in a query\")\n\t}\n\tif (parsedQuery.closeTime != nil || parsedQuery.startTime != nil) && parsedQuery.searchPrecision == nil {\n\t\treturn nil, errors.New(\"SearchPrecision is required when searching for a StartTime or CloseTime\")\n\t}\n\n\tif parsedQuery.closeTime == nil && parsedQuery.startTime == nil && parsedQuery.searchPrecision != nil {\n\t\treturn nil, errors.New(\"SearchPrecision requires a StartTime or CloseTime\")\n\t}\n\treturn parsedQuery, nil\n}\n\nfunc (p *queryParser) convertWhereExpr(expr sqlparser.Expr, parsedQuery *parsedQuery) error {\n\tif expr == nil {\n\t\treturn errors.New(\"where expression is nil\")\n\t}\n\n\tswitch expr := expr.(type) {\n\tcase *sqlparser.ComparisonExpr:\n\t\treturn p.convertComparisonExpr(expr, parsedQuery)\n\tcase *sqlparser.AndExpr:\n\t\treturn p.convertAndExpr(expr, parsedQuery)\n\tcase *sqlparser.ParenExpr:\n\t\treturn p.convertParenExpr(expr, parsedQuery)\n\tdefault:\n\t\treturn errors.New(\"only comparison and \\\"and\\\" expression is supported\")","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/temporalio/temporal/blob/bde624efd13fbd3843654058db6d9c716166318b/common/archiver/s3store/query_parser.go#L61-L97","documentation":"SearchPrecision is only meaningful as a companion to a StartTime or CloseTime filter; it tells the parser how to bound the archive scan window. Parse rejects a query that includes SearchPrecision with neither time field.","triggerScenarios":"Calling Parse with e.g. \"WorkflowId = 'w1' AND SearchPrecision = 'Day'\" — parsedQuery.searchPrecision is set but both closeTime and startTime are nil.","commonSituations":"Query builders that always append SearchPrecision regardless of whether a time filter was supplied; users copying query templates that include SearchPrecision while removing the time condition.","solutions":["Remove the SearchPrecision predicate if no time filter is needed.","Add the intended StartTime or CloseTime condition alongside SearchPrecision (remembering only one time field is allowed).","Fix query-builder logic so SearchPrecision is emitted only when a time predicate is present."],"exampleFix":"// before\nparser.Parse(\"WorkflowId = 'w1' AND SearchPrecision = 'Hour'\")\n// after\nparser.Parse(\"WorkflowId = 'w1'\")","handlingStrategy":"validation","validationCode":"hasTime := strings.Contains(query, \"StartTime\") || strings.Contains(query, \"CloseTime\")\nif strings.Contains(query, \"SearchPrecision\") && !hasTime {\n    return errors.New(\"SearchPrecision only makes sense with a StartTime or CloseTime filter\")\n}","typeGuard":null,"tryCatchPattern":"pq, err := parser.Parse(query)\nif err != nil {\n    if strings.Contains(err.Error(), \"SearchPrecision requires\") {\n        return nil, status.Error(codes.InvalidArgument, err.Error())\n    }\n    return nil, err\n}","preventionTips":["Emit SearchPrecision only in conjunction with a time predicate in query builders.","Strip dangling SearchPrecision when removing time filters from a query template."],"tags":["go","archival","query-validation","s3store"],"backgroundTag":"orphaned-query-parameter","analyzedSha":"bde624efd13fbd3843654058db6d9c716166318b","analyzedAt":"2026-09-01T07:18:39.080Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}