Skip to content

ArrayField contains lookup crashes with Exists #204

@timgraham

Description

@timgraham

I'm unsure if it's feasible to implement. The solution may be to raise NotSupportedError.

>>> inner_qs = IntegerArrayModel.objects.filter(field__contains=OuterRef("field"))`
>>> NullableIntegerArrayModel.objects.filter(Exists(inner_qs))
...
PlanExecutor error during aggregation :: caused by :: both operands of $setIsSubset must be arrays. First argument is of type: null
db.model_fields__nullableintegerarraymodel.aggregate([
    {
        "$lookup": {
            "as": "__subquery0",
            "from": "model_fields__integerarraymodel",
            "let": {},
            "pipeline": [
                {"$match": {"$expr": {}}},
                {"$project": {"field": 1}},
                {"$limit": 1},
            ],
        }
    },
    {
        "$set": {
            "__subquery0": {
                "$cond": {
                    "if": {
                        "$or": [
                            {"$eq": [{"$type": "$__subquery0"}, "missing"]},
                            {"$eq": [{"$size": "$__subquery0"}, 0]},
                        ]
                    },
                    "then": {},
                    "else": {"$arrayElemAt": ["$__subquery0", 0]},
                }
            }
        }
    },
    {
        "$match": {
            "$expr": {
                "$eq": [
                    {
                        "$cond": {
                            "if": {"$eq": ["$field", None]},
                            "then": FALSE,
                            "else": {"$setIsSubset": ["$__subquery0.field", "$field"]},
                        }
                    },
                    TRUE,
                ]
            }
        }
    },
]);

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions