Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArrayField contains lookup crashes with Exists #204

Open
timgraham opened this issue Jan 2, 2025 · 0 comments
Open

ArrayField contains lookup crashes with Exists #204

timgraham opened this issue Jan 2, 2025 · 0 comments

Comments

@timgraham
Copy link
Collaborator

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,
                ]
            }
        }
    },
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant