Add support for extended subquery comparison in compare_queries().

Review Request #13402 — Created Nov. 6, 2023 and submitted — Latest diff uploaded

Information

Djblets
release-3.x

Reviewers

This reworks query comparison in compare_queries() and
assertQueries() to track and compare nested subqueries. Queries now
support a subqueries field, which follows the same format of the main
expected queries list, and this can be nested as deeply as required for
the queries being executed.

Any subquery inside of a where filter (via Subquery() or Exists())
will be transformed into a Q(__SubqueryType__subquery__=index) query,
since this allows for direct comparison and equates to an index within
the nested query comparison list.

The recent support for inner_query has been removed in favor of this
new support. Support is opt-in currently for assertQueries(), to
maintain backwards-compatibility, but will be enabled by default in
Djblets 5.

The normalization and formatting support has been enhanced to support
subqueries and F-expressions, and to display the way the code would be
written in Python with Q(...), F(...), etc. This makes it far easier
to compare and update queries.

Unit tests pass.

Tested this with in-progress code in Review Board.

Diff Revision 2

This is not the most recent revision of the diff. The latest diff is revision 6. See what's changed.

orig
1
2
3
4
5
6

Commits

First Last Summary ID Author
Add support for extended subquery comparison in compare_queries().
This reworks query comparison in `compare_queries()` and `assertQueries()` to track and compare nested subqueries. Queries now support a `subqueries` field, which follows the same format of the main expected queries list, and this can be nested as deeply as required for the queries being executed. Any subquery inside of a `where` filter (via `Subquery()` or `Exists()`) will be transformed into a `Q(__SubqueryType__subquery__=index)` query, since this allows for direct comparison and equates to an index within the nested query comparison list. The recent support for `inner_query` has been removed in favor of this new support. Support is opt-in currently for `assertQueries()`, to maintain backwards-compatibility, but will be enabled by default in Djblets 5. The normalization and formatting support has been enhanced to support subqueries and F-expressions, and to display the way the code would be written in Python with `Q(...)`, `F(...)`, etc. This makes it far easier to compare and update queries.
651308090d58b1ff905af35eb509f664c57fa98e Christian Hammond
djblets/db/query_comparator.py
djblets/db/tests/test_query_comparator.py
djblets/testing/testcases.py
Loading...