{"record":{"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/6e10b029c1326a437932a8b24f38af69fd986e15/boto3/dynamodb/conditions.py#L17-L53","documentation":"DynamoDB condition expressions are built from ConditionBase objects (And, Or, Not, Equals, etc.). When you use the & operator on a ConditionBase instance with something that is not itself a ConditionBase, boto3 raises DynamoDBOperationNotSupportedError('AND', other). The library cannot fold a raw Python value into a condition expression because there is no defined mapping from arbitrary types to a DynamoDB condition.","triggerScenarios":"Writing Key('pk').eq('x') & 'some_string', Attr('n').lt(5) & True, or chaining & with a previously-rendered string/expression. Also occurs when an operand is None because a condition variable was never assigned.","commonSituations":"Building filter_expression or key_condition_expression dynamically where one branch accidentally yields None or a scalar; refactoring a query and leaving a placeholder value; confusing the logical-and of two conditions (both ConditionBase) with comparing an attribute to a value.","solutions":["Ensure both operands of & are ConditionBase instances produced by Attr()/Key() comparison methods (eq, lt, gt, begins_with, etc.).","Guard dynamic condition building: only apply & when the candidate is an instance of ConditionBase, otherwise wrap it with Attr(name).eq(value).","If a variable may be None, default it to a neutral condition or skip the & operation entirely."],"exampleFix":"# before\ncond = Attr('status').eq('ACTIVE') & maybe_filter  # maybe_filter may be None\n# after\ncond = Attr('status').eq('ACTIVE')\nif maybe_filter is not None:\n    cond = cond & maybe_filter","handlingStrategy":"type-guard","validationCode":"from boto3.dynamodb.conditions import ConditionBase\nassert isinstance(left, ConditionBase) and isinstance(right, ConditionBase), \\\n    'Both operands of & must be ConditionBase instances'","typeGuard":"from boto3.dynamodb.conditions import ConditionBase\ndef is_condition(v) -> bool:\n    return isinstance(v, ConditionBase)","tryCatchPattern":"from boto3.exceptions import DynamoDBOperationNotSupportedError\ntry:\n    expr = base & extra\nexcept DynamoDBOperationNotSupportedError:\n    extra = Attr('fallback').eq(True)\n    expr = base & extra","preventionTips":["Never & raw values; always Attr()/Key().method().","When building dynamic conditions, type-check operands before combining.","Default optional conditions to None and branch instead of &-ing them."],"tags":["dynamodb","conditions","expression","boto3"],"backgroundTag":null,"analyzedSha":"6e10b029c1326a437932a8b24f38af69fd986e15","analyzedAt":"2026-08-11T20:52:47.213Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}