{"record":{"id":"0d9131f98865e79a","repo":"Kareadita/Kavita","slug":"comparison-is-not-applicable-for-fieldname","errorCode":null,"errorMessage":"{comparison} is not applicable for {fieldName}","messagePattern":"(.+?) is not applicable for (.+?)","errorType":"exception","errorClass":"KavitaException","httpStatus":400,"severity":"warning","filePath":"Kavita.Database/Extensions/Filters/ComparisonProfile.cs","lineNumber":84,"sourceCode":"    [\n        FilterComparison.Equal, FilterComparison.NotEqual,\n        FilterComparison.GreaterThan, FilterComparison.GreaterThanEqual,\n        FilterComparison.LessThan, FilterComparison.LessThanEqual,\n        FilterComparison.IsBefore, FilterComparison.IsAfter,\n        FilterComparison.IsInLast, FilterComparison.IsNotInLast,\n        FilterComparison.IsEmpty, FilterComparison.IsNotEmpty\n    ];\n\n    /// <summary>\n    /// Throws <see cref=\"KavitaException\"/> if the comparison is not in the allowed set.\n    /// </summary>\n    /// <param name=\"comparison\">The comparison to validate</param>\n    /// <param name=\"allowed\">The set of allowed comparisons for this field</param>\n    /// <param name=\"fieldName\">The field name for the error message (e.g. \"Person.Name\")</param>\n    public static void Validate(FilterComparison comparison, HashSet<FilterComparison> allowed, string fieldName)\n    {\n        if (!allowed.Contains(comparison))\n            throw new KavitaException($\"{comparison} is not applicable for {fieldName}\");\n    }\n}\n","sourceCodeStart":66,"sourceCodeEnd":87,"githubUrl":"https://github.com/Kareadita/Kavita/blob/9c3e5400007f8a0282f7d883f2ad5e71716e514d/Kavita.Database/Extensions/Filters/ComparisonProfile.cs#L66-L87","documentation":"Thrown by ComparisonProfile.Validate when a FilterComparison enum value is not in the allowed set for a given field type (String/Numeric/List/Date sets defined in ComparisonProfile.cs). Example: GreaterThan on a string field, or IsBefore on a numeric field. Message is interpolated as '{comparison} is not applicable for {fieldName}'.","triggerScenarios":"A smart-filter / API filter request sends a predicate whose comparison operator is invalid for that field's type — e.g. matching Person.Name with FilterComparison.GreaterThan, or a date-only operator (IsInLast) on a numeric field. Validation runs at the top of each filter-building method.","commonSituations":"Frontend dropdown sends a stale operator after the field type changed; hand-built filter JSON with a wrong comparison; a newly added field whose allowed-set wasn't updated in ComparisonProfile.","solutions":["Send only the comparison operators the field type allows per ComparisonProfile (String/Numeric/List/Date sets).","On the client, constrain the operator dropdown to the field type's valid set before submitting.","If you added a new field type, ensure its allowed FilterComparison set in ComparisonProfile is correct."],"exampleFix":"// before - GreaterThan on a string field\nComparisonProfile.Validate(FilterComparison.GreaterThan, ComparisonProfile.String, \"Person.Name\");\n\n// after - use an operator valid for string fields\nComparisonProfile.Validate(FilterComparison.Matches, ComparisonProfile.String, \"Person.Name\");","handlingStrategy":"validation","validationCode":"if (!allowedSet.Contains(requestedComparison))\n    return BadRequest($\"{requestedComparison} is not valid for {field}\");","typeGuard":"static bool IsValidComparison(FilterComparison c, HashSet<FilterComparison> allowed)\n    => allowed.Contains(c);","tryCatchPattern":"try { ComparisonProfile.Validate(comp, ComparisonProfile.String, \"Name\"); }\ncatch (KavitaException ex) { return BadRequest(ex.Message); }","preventionTips":["Constrain client operator dropdowns to the field type's allowed set.","Call ComparisonProfile.Validate explicitly before building a predicate.","Keep the allowed-set map in sync when adding new fields."],"tags":["filtering","validation","smart-filter","input"],"backgroundTag":null,"analyzedSha":"9c3e5400007f8a0282f7d883f2ad5e71716e514d","analyzedAt":"2026-08-13T19:06:05.897Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}