{"record":{"id":"680997289d1c1893","repo":"actualbudget/actual","slug":"casting-string-fields-to-dates-is-not-supported","errorCode":null,"errorMessage":"Casting string fields to dates is not supported","messagePattern":"Casting string fields to dates is not supported","errorType":"exception","errorClass":"CompileError","httpStatus":null,"severity":"error","filePath":"packages/loot-core/src/server/aql/compiler.ts","lineNumber":269,"sourceCode":"    return typed(expr.value, type);\n  } else if (expr.type === 'null') {\n    if (!expr.literal) {\n      throw new CompileError(\"A non-literal null doesn't make sense\");\n    }\n\n    if (type === 'boolean') {\n      return typed(0, 'boolean', { literal: true });\n    }\n    return expr;\n  }\n\n  // These are all things that can be safely casted automatically\n  if (type === 'date') {\n    if (expr.type === 'string') {\n      if (expr.literal) {\n        return parseDate(expr.value) || badDateFormat(expr.value, 'date');\n      } else {\n        throw new CompileError(\n          'Casting string fields to dates is not supported',\n        );\n      }\n    }\n\n    throw new CompileError(`Can't cast ${expr.type} to date`);\n  } else if (type === 'date-month') {\n    let expr2;\n    if (expr.type === 'date') {\n      expr2 = expr;\n    } else if (expr.type === 'string' || expr.type === 'any') {\n      expr2 =\n        parseMonth(expr.value) ||\n        parseDate(expr.value) ||\n        badDateFormat(expr.value, 'date-month');\n    } else {\n      throw new CompileError(`Can't cast ${expr.type} to date-month`);\n    }","sourceCodeStart":251,"sourceCodeEnd":287,"githubUrl":"https://github.com/actualbudget/actual/blob/d4334cb6e6123f4d3bcea1ad6166608884c7e658/packages/loot-core/src/server/aql/compiler.ts#L251-L287","documentation":"castInput (compiler.ts:264) can auto-cast only literal strings into dates. If the expression is a non-literal string (e.g. a string column/field reference), the compiler cannot convert it at compile time, so it throws this CompileError — string fields must be transformed explicitly, not implicitly cast.","triggerScenarios":"Comparing a string field to a date in a filter where the string side is a field reference rather than a literal, e.g. building expressions where a non-literal string expr is used where a date type is required.","commonSituations":"Queries comparing two columns of mismatched types (string field vs date field); custom rules/reports referencing string columns inside date functions; migration of queries after type checking tightened.","solutions":["Use $transform with $date/$datemachine-style functions to explicitly convert the string field before date comparison.","Ensure the value being compared is a literal date string (auto-parsed) or a genuine date field, not a raw string column.","If the column holds machine dates, compare it as a string/date-machinable value rather than forcing a date cast."],"exampleFix":"// before\n.filter({ imported_date: { $gte: '2024-01-01' } }) // imported_date is a string field in a date op\n// after\n.transform({ imported_date: { $date: '$imported_date' } })\n .filter({ imported_date: { $gte: '2024-01-01' } })","handlingStrategy":"validation","validationCode":"function assertDateComparable(expr) {\n  // only literal strings or date-typed fields may take part in date comparisons\n  if (expr.kind === 'field' && expr.type === 'string') {\n    throw new Error('Convert string field with $transform/$date before date comparison');\n  }\n}","typeGuard":"function isDateTyped(fieldDesc) {\n  return fieldDesc != null && (fieldDesc.type === 'date' || String(fieldDesc.type).startsWith('date-'));\n}","tryCatchPattern":"try {\n  runQuery(q);\n} catch (e) {\n  if (e.message.includes('Casting string fields to dates is not supported')) {\n    throw new Error('Transform the string field to a date explicitly first');\n  } else throw e;\n}","preventionTips":["Only compare date-typed fields or literal date strings in date operations","Use $transform date conversions for string columns","Check field types in the AQL schema before writing comparisons"],"tags":["aql","date","casting","compile-error"],"backgroundTag":"unsupported-type-cast","analyzedSha":"d4334cb6e6123f4d3bcea1ad6166608884c7e658","analyzedAt":"2026-08-29T01:02:11.213Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}