{"id":"1c013aeff2251ee0","repo":"boto/boto3","slug":"and-operation-cannot-be-applied-to-value-value-o","errorCode":null,"errorMessage":"AND 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":"AND 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":35,"sourceCode":"    DynamoDBNeedsConditionError,\n    DynamoDBNeedsKeyConditionError,\n    DynamoDBOperationNotSupportedError,\n)\n\nATTR_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):","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/boto/boto3/blob/c7b4afac237b976d48395d7523eaf7cec3a450b3/boto3/dynamodb/conditions.py#L17-L53","documentation":"Raised by ConditionBase.__and__ when the & operator is applied between a ConditionBase (e.g. the result of Attr('x').eq(1)) and an operand that is NOT a ConditionBase. DynamoDB condition expressions can only be combined (&) with other conditions; combining a condition with a raw value, string, dict, or number is invalid because the library cannot build a valid DynamoDB FilterExpression/ConditionExpression from a non-condition.","triggerScenarios":"table.scan(FilterExpression=Attr('status').eq('active') & 'pending') — the right operand 'pending' is a str, not a ConditionBase. Also Attr('n').eq(1) & 2 or Attr('n').eq(1) & {'x': 1}.","commonSituations":"Forgetting to call .eq()/.gt()/.begins_with() on the second attribute operand; accidentally short-circuiting with a literal; copy-paste where one side of the & was truncated.","solutions":["Ensure BOTH operands of & are ConditionBase instances, e.g. Attr('status').eq('active') & Attr('pending').eq(True).","Check the right-hand operand with isinstance(other, ConditionBase) before combining.","Chain conditions incrementally and assert each intermediate result is a condition."],"exampleFix":"# before\nfe = Attr('status').eq('active') & 'pending'\ntable.scan(FilterExpression=fe)\n\n# after\nfe = Attr('status').eq('active') & Attr('status').eq('pending')\ntable.scan(FilterExpression=fe)","handlingStrategy":"type-guard","validationCode":"from boto3.dynamodb.conditions import ConditionBase\n\ndef safe_and(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    # other was not a condition; build a proper condition instead\n    expr = cond_a & Attr('field').eq(other)","preventionTips":["Always call a comparison method (.eq, .gt, .begins_with, ...) on every Attr/Key before combining.","Lint DynamoDB filter expressions with isinstance checks during development.","Keep conditions as named variables so partial constructions are visible."],"tags":["dynamodb","conditions","filter-expression","operator"],"analyzedSha":"c7b4afac237b976d48395d7523eaf7cec3a450b3","analyzedAt":"2026-08-04T20:35:51.598Z","schemaVersion":2}