{"record":{"id":"169e39195c0b526a","repo":"microsoft/semantic-kernel","slug":"unsupported-operator-type-op-169e39","errorCode":null,"errorMessage":"Unsupported operator: {type(op)}","messagePattern":"Unsupported operator: (.+?)","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/mongodb.py","lineNumber":479,"sourceCode":"                match op:\n                    case ast.In():\n                        return {left: {\"$in\": right}}\n                    case ast.NotIn():\n                        return {left: {\"$nin\": right}}\n                    case ast.Eq():\n                        # MongoDB allows short form: {field: value}\n                        return {left: right}\n                    case ast.NotEq():\n                        return {left: {\"$ne\": right}}\n                    case ast.Gt():\n                        return {left: {\"$gt\": right}}\n                    case ast.GtE():\n                        return {left: {\"$gte\": right}}\n                    case ast.Lt():\n                        return {left: {\"$lt\": right}}\n                    case ast.LtE():\n                        return {left: {\"$lte\": right}}\n                raise NotImplementedError(f\"Unsupported operator: {type(op)}\")\n            case ast.BoolOp():\n                op = node.op  # type: ignore\n                values = [self._lambda_parser(v) for v in node.values]\n                if isinstance(op, ast.And):\n                    return {\"$and\": values}\n                if isinstance(op, ast.Or):\n                    return {\"$or\": values}\n                raise NotImplementedError(f\"Unsupported BoolOp: {type(op)}\")\n            case ast.UnaryOp():\n                match node.op:\n                    case ast.Not():\n                        operand = self._lambda_parser(node.operand)\n                        return {\"$not\": operand}\n                    case ast.UAdd() | ast.USub() | ast.Invert():\n                        raise NotImplementedError(\"Unary +, -, ~ are not supported in MongoDB filters.\")\n            case ast.Attribute():\n                # Only allow attributes that are in the data model\n                if node.attr not in self.definition.storage_names:","sourceCodeStart":461,"sourceCodeEnd":497,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/mongodb.py#L461-L497","documentation":"The MongoDB Atlas collection filter parser walks the AST of a lambda predicate and translates Python comparison operators into MongoDB query operators. This NotImplementedError fires when the lambda contains a comparison operator that the parser has no mapping for — currently only In, NotIn, Eq, NotEq, Gt, GtE, Lt, LtE are handled. Any other ast.cmpop subclass (e.g. Is, IsNot, IsInstance patterns) falls through all match cases and reaches the raise.","triggerScenarios":"Calling a collection search/get with a lambda filter that uses identity comparison (`x is y`, `x is not y`) or any operator outside the eight supported cmpop types. For example `lambda x: x.field Is None`-style logic, or using `is`/`is not` inside the predicate passed to the vector store collection.","commonSituations":"Developer writes a filter lambda using Python identity operators (`is`, `is not`) thinking they behave like equality. Developer uses comparison against `None` with `is` instead of `==`. Migrating from a SQL or ORM filter that supports richer operators.","solutions":["Rewrite the filter lambda to use only supported operators: ==, !=, >, >=, <, <=, `in`, `not in`.","Replace any `x is None` with `x == None` (or better, restructure the filter to avoid null checks the parser cannot express).","If you need a condition the parser does not support, pre-filter results in application code after the query instead of inside the lambda."],"exampleFix":"// before\ncollection.search(filter=lambda x: x.status is not None)\n// after\ncollection.search(filter=lambda x: x.status != None)","handlingStrategy":"validation","validationCode":"SUPPORTED_OPS = (ast.Eq, ast.NotEq, ast.Gt, ast.GtE, ast.Lt, ast.LtE, ast.In, ast.NotIn)\nimport ast\ndef validate_filter_lambda(func):\n    tree = ast.parse(inspect.getsource(func))\n    for node in ast.walk(tree):\n        if isinstance(node, ast.Compare):\n            for op in node.ops:\n                if not isinstance(op, SUPPORTED_OPS):\n                    raise ValueError(f\"Unsupported comparison operator: {type(op).__name__}\")","typeGuard":null,"tryCatchPattern":"try:\n    results = await collection.search(filter=my_lambda)\nexcept NotImplementedError as e:\n    if \"Unsupported operator\" in str(e):\n        # rewrite the filter using only ==, !=, >, >=, <, <=, in, not in\n        ...","preventionTips":["Restrict filter lambdas to the eight supported comparison operators: ==, !=, >, >=, <, <=, in, not in.","Never use identity operators (is, is not) in MongoDB filter lambdas.","Write a small unit test that exercises your filter lambda against the collection before deploying."],"tags":["mongodb","filter","lambda","ast","semantic-kernel"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}