medusajs/medusa · error · MedusaError
Rule attribute must be a string
Error message
Rule attribute must be a string
What it means
Within validateRule, the rule's attribute must be a string. Passing a number, object, or symbol as attribute throws INVALID_DATA.
Source
Thrown at packages/modules/fulfillment/src/utils/utils.ts:107
}
return loopComparator.apply(rules, [predicate])
}
/**
* Validate contextValue rule object
* @param rule
*/
export function validateRule(rule: Record<string, unknown>): boolean {
if (!rule.attribute || !rule.operator || !rule.value) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
"Rule must have an attribute, an operator and a value"
)
}
if (!isString(rule.attribute)) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
"Rule attribute must be a string"
)
}
if (!isString(rule.operator)) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
"Rule operator must be a string"
)
}
if (!availableOperators.includes(rule.operator as RuleOperator)) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
`Rule operator ${
rule.operator
} is not supported. Must be one of ${availableOperators.join(", ")}`View on GitHub (pinned to 5e06e544a2)
Solutions
- Coerce/validate attribute to a string before calling the service
- Use known attribute identifiers as string constants
Example fix
// before
rules: [{ attribute: 42, operator: 'eq', value: 'x' }]
// after
rules: [{ attribute: String(42), operator: 'eq', value: 'x' }]) Defensive patterns
Strategy: type-guard
Type guard
const hasStringAttribute = (r: any): boolean => typeof r?.attribute === 'string' && r.attribute.length > 0
Prevention
- Type rule inputs as { attribute: string; operator: string; value: unknown }
- Coerce imported values with String() before building rules
When it happens
Trigger: Programmatically building rules with computed keys or unserialized values, e.g. { attribute: 123, ... } or attribute taken from untyped JSON input.
Common situations: CSV/external imports mapping columns to attributes without coercing to string; client sending numeric attribute identifiers.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Rule operator must be a string
- The following rules does not exists: ${Array.from(nonAlready
- Rule must have an attribute, an operator and a value
- Rule operator ${rule.operator} is not supported. Must be one
- Rule value must be an array for in/nin operators
AI-assisted analysis of medusajs/medusa@5e06e544a2 (2026-08-27).
Data as JSON: /api/errors/bea602fb97fa2a17.
Report an issue: GitHub.