{"id":"99c4ca6cb38bbd48","repo":"boto/boto3","slug":"expecting-a-conditionbase-object-got-value-of-t","errorCode":null,"errorMessage":"Expecting a ConditionBase object. Got {value} of type {type(value)}. Use AttributeBase object methods (i.e. Attr().eq()). to generate ConditionBase instances.","messagePattern":"Expecting a ConditionBase object\\. Got (.+?) of type (.+?)\\. Use AttributeBase object methods \\(i\\.e\\. Attr\\(\\)\\.eq\\(\\)\\)\\. to generate ConditionBase instances\\.","errorType":"exception","errorClass":"DynamoDBNeedsConditionError","httpStatus":null,"severity":"error","filePath":"boto3/dynamodb/conditions.py","lineNumber":344,"sourceCode":"\n        :type condition: ConditionBase\n        :param condition: A condition to be built into a condition expression\n            string with any necessary placeholders.\n\n        :type is_key_condition: Boolean\n        :param is_key_condition: True if the expression is for a\n            KeyConditionExpression. False otherwise.\n\n        :rtype: (string, dict, dict)\n        :returns: Will return a string representing the condition with\n            placeholders inserted where necessary, a dictionary of\n            placeholders for attribute names, and a dictionary of\n            placeholders for attribute values. Here is a sample return value:\n\n            ('#n0 = :v0', {'#n0': 'myattribute'}, {':v1': 'myvalue'})\n        \"\"\"\n        if not isinstance(condition, ConditionBase):\n            raise DynamoDBNeedsConditionError(condition)\n        attribute_name_placeholders = {}\n        attribute_value_placeholders = {}\n        condition_expression = self._build_expression(\n            condition,\n            attribute_name_placeholders,\n            attribute_value_placeholders,\n            is_key_condition=is_key_condition,\n        )\n        return BuiltConditionExpression(\n            condition_expression=condition_expression,\n            attribute_name_placeholders=attribute_name_placeholders,\n            attribute_value_placeholders=attribute_value_placeholders,\n        )\n\n    def _build_expression(\n        self,\n        condition,\n        attribute_name_placeholders,","sourceCodeStart":326,"sourceCodeEnd":362,"githubUrl":"https://github.com/boto/boto3/blob/c7b4afac237b976d48395d7523eaf7cec3a450b3/boto3/dynamodb/conditions.py#L326-L362","documentation":"Raised by ConditionExpressionBuilder.build_expression() when the object passed as a condition is not a ConditionBase. The builder recurses through the condition tree emitting placeholders; a non-condition (raw value, bare Attr/Key, or unrelated object) cannot be processed. This is typically surfaced when a table.query / table.scan / item.update receives a FilterExpression, ConditionExpression, or KeyConditionExpression that is not a fully-built condition.","triggerScenarios":"table.query(KeyConditionExpression=Key('pk')) — missing .eq()/.begins_with(); table.scan(FilterExpression=Attr('x')) — bare Attr; passing a plain dict or string to FilterExpression.","commonSituations":"Forgetting the terminal comparison method on Key/Attr; passing a raw attribute name string instead of a condition object; refactoring that drops the final method call.","solutions":["Ensure the expression is a ConditionBase: table.query(KeyConditionExpression=Key('pk').eq('v')).","For filter expressions, call a comparison/method on Attr: Attr('x').eq(1) or Attr('x').exists().","If you must build from strings, use raw KeyConditionExpression strings with explicit placeholders instead of the builder."],"exampleFix":"# before\ntable.query(KeyConditionExpression=Key('pk'))\n\n# after\ntable.query(KeyConditionExpression=Key('pk').eq('user#1'))","handlingStrategy":"type-guard","validationCode":"from boto3.dynamodb.conditions import ConditionBase\n\ndef check_expression(expr):\n    if not isinstance(expr, ConditionBase):\n        raise TypeError(f'Expected ConditionBase, got {type(expr).__name__}')\n    return expr","typeGuard":"from boto3.dynamodb.conditions import ConditionBase\n\ndef is_condition(v) -> bool:\n    return isinstance(v, ConditionBase)","tryCatchPattern":"from boto3.exceptions import DynamoDBNeedsConditionError\ntry:\n    table.scan(FilterExpression=expr)\nexcept DynamoDBNeedsConditionError:\n    # expr was not a built condition; rebuild it\n    table.scan(FilterExpression=Attr('x').eq(expr))","preventionTips":["Always terminate Key()/Attr() chains with a comparison or function method.","Wrap expression construction in a helper that asserts isinstance(..., ConditionBase).","Write unit tests for DynamoDB query/scan calls so malformed expressions fail early."],"tags":["dynamodb","conditions","filter-expression","key-condition","builder"],"analyzedSha":"c7b4afac237b976d48395d7523eaf7cec3a450b3","analyzedAt":"2026-08-04T20:35:51.598Z","schemaVersion":2}