{"id":"da5edcc0e659b018","repo":"boto/boto3","slug":"or-operation-cannot-be-applied-to-value-value-of","errorCode":null,"errorMessage":"OR operation cannot be applied to value {value} of type {type(value)} directly. Must use AttributeBase object methods (i.e. Attr().eq()). to generate ConditionBase instances first.","messagePattern":"OR operation cannot be applied to value (.+?) of type (.+?) directly\\. Must use AttributeBase object methods \\(i\\.e\\. Attr\\(\\)\\.eq\\(\\)\\)\\. to generate ConditionBase instances first\\.","errorType":"exception","errorClass":"DynamoDBOperationNotSupportedError","httpStatus":null,"severity":"error","filePath":"boto3/dynamodb/conditions.py","lineNumber":40,"sourceCode":"ATTR_NAME_REGEX = re.compile(r'[^.\\[\\]]+(?![^\\[]*\\])')\n\n\nclass ConditionBase:\n    expression_format = ''\n    expression_operator = ''\n    has_grouped_values = False\n\n    def __init__(self, *values):\n        self._values = values\n\n    def __and__(self, other):\n        if not isinstance(other, ConditionBase):\n            raise DynamoDBOperationNotSupportedError('AND', other)\n        return And(self, other)\n\n    def __or__(self, other):\n        if not isinstance(other, ConditionBase):\n            raise DynamoDBOperationNotSupportedError('OR', other)\n        return Or(self, other)\n\n    def __invert__(self):\n        return Not(self)\n\n    def get_expression(self):\n        return {\n            'format': self.expression_format,\n            'operator': self.expression_operator,\n            'values': self._values,\n        }\n\n    def __eq__(self, other):\n        if isinstance(other, type(self)):\n            if self._values == other._values:\n                return True\n        return False\n","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/boto/boto3/blob/c7b4afac237b976d48395d7523eaf7cec3a450b3/boto3/dynamodb/conditions.py#L22-L58","documentation":"Raised by ConditionBase.__or__ when the | operator is applied between a ConditionBase and an operand that is not a ConditionBase. Same principle as the AND variant: OR in DynamoDB condition expressions requires both sides to be conditions so the library can emit a valid OR node in the expression tree.","triggerScenarios":"table.scan(FilterExpression=Attr('status').eq('active') | 'archived') — the right operand is a bare string. Also Attr('n').eq(1) | 5 or any | with a non-ConditionBase.","commonSituations":"Mixing up OR with attribute_exists/attribute_not_exists shorthand; forgetting .eq() on the second side; treating | like a bitwise OR on values.","solutions":["Make the right operand a ConditionBase: Attr('status').eq('active') | Attr('status').eq('archived').","Validate with isinstance(right, ConditionBase) before |.","Use Attr(...).is_in([...]) when OR-ing equality on the same attribute."],"exampleFix":"# before\nfe = Attr('status').eq('active') | 'archived'\n\n# after\nfe = Attr('status').eq('active') | Attr('status').eq('archived')\n# or equivalently\nfe = Attr('status').is_in(['active', 'archived'])","handlingStrategy":"type-guard","validationCode":"from boto3.dynamodb.conditions import ConditionBase\n\ndef safe_or(left, right):\n    if not isinstance(right, ConditionBase):\n        raise TypeError(f'Right operand of | must be a ConditionBase, got {type(right)}')\n    return left | right","typeGuard":"from boto3.dynamodb.conditions import ConditionBase\n\ndef is_condition(v) -> bool:\n    return isinstance(v, ConditionBase)","tryCatchPattern":"from boto3.exceptions import DynamoDBOperationNotSupportedError\ntry:\n    expr = cond_a | other\nexcept DynamoDBOperationNotSupportedError:\n    expr = cond_a | Attr('field').eq(other)","preventionTips":["Use Attr(...).is_in([...]) instead of chaining multiple | when OR-ing equality checks.","Verify every operand in a compound expression is a ConditionBase.","Name each sub-condition so a truncated operand is obvious."],"tags":["dynamodb","conditions","filter-expression","operator"],"analyzedSha":"c7b4afac237b976d48395d7523eaf7cec3a450b3","analyzedAt":"2026-08-04T20:35:51.598Z","schemaVersion":2}