Skip to content
New issue

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

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

Already on GitHub? # to your account

Union Subquery Not Mapping Parent Parameters and Collections Properly. #156

Open
WaVEV opened this issue Oct 10, 2024 · 0 comments
Open

Comments

@WaVEV
Copy link
Collaborator

WaVEV commented Oct 10, 2024

Fix these tests:
queries.test_qs_combinators.QuerySetSetOperationTests.test_union_in_subquery_related_outerref
queries.test_qs_combinators.QuerySetSetOperationTests.test_union_in_subquery

The first one generates the following query:

[{'$lookup': {'as': 'queries_extrainfo',
              'from': 'queries_extrainfo',
              'let': {'parent__field__0': {'$convert': {'input': '$extra_id',
                                                        'to': 'string'}}},
              'pipeline': [{'$match': {'$expr': {'$and': [{'$eq': ['$$parent__field__0',
                                                                   {'$convert': {'input': '$_id',
                                                                                 'to': 'string'}}]}]}}}]}},
 {'$unwind': '$queries_extrainfo'},
 {'$lookup': {'as': '__subquery0',
              'from': 'queries_extrainfo',
              'let': {},
              'pipeline': [{'$match': {'$expr': {'$eq': ['$value',
                                                         '$$parent__field__0']}}},
                           {'$project': {'info': 1}},
                           {'$project': {'info': 1}},
                           {'$unionWith': {'coll': 'U0',
                                           'pipeline': [{'$match': {'$expr': {'$lt': ['$value',
                                                                                      '$$parent__field__0']}}},
                                                        {'$project': {'info': 1}},
                                                        {'$project': {'info': 1}}]}},
                           {'$group': {'_id': {'info': '$info'}}},
                           {'$addFields': {'info': '$_id.info'}},
                           {'$unset': '_id'},
                           {'$limit': 1}]}},
 {'$set': {'__subquery0': {'$cond': {'else': {'$arrayElemAt': ['$__subquery0',
                                                               0]},
                                     'if': {'$or': [{'$eq': [{'$type': '$__subquery0'},
                                                             'missing']},
                                                    {'$eq': [{'$size': '$__subquery0'},
                                                             0]}]},
                                     'then': {}}}}},
 {'$match': {'$expr': {'$not': {'$or': [{'$eq': [{'$type': '$__subquery0.info'},
                                                 'missing']},
                                        {'$eq': ['$__subquery0.info',
                                                 None]}]}}}},
 {'$project': {'name': 1}},
 {'$sort': SON([('name', 1)])}]

Note the Coll: U0 is wrong, we are using the alias instead of the real collection.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant