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

Tech : assertSnapshotQueries() avec des annotations chainées #4777

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,35 @@ def make_unordered_queries_randomly_ordered():
)


@pytest.fixture(scope="session", autouse=True)
def fix_unstable_annotation_order():
"""
Patch Django’s ORM to have the annotation stable in the SQL produced by .count() calls.

The annotation_mask order is then used in annotation_select property
cf https://github.com/django/django/blob/stable/5.0.x/django/db/models/sql/query.py#L2519

This patch however will stop working with https://github.com/django/django/commit/65ad4ade74d

"""
from django.db.models.sql.query import Query

patchy.patch(
Query.get_aggregation,
"""\
@@ -104,7 +104,7 @@
for annotation_alias, annotation in self.annotation_select.items():
if annotation.get_group_by_cols():
annotation_mask.add(annotation_alias)
- inner_query.set_annotation_mask(annotation_mask)
+ inner_query.set_annotation_mask(sorted(annotation_mask))

# Add aggregates to the outer AggregateQuery. This requires making
# sure all columns referenced by the aggregates are selected in the
""",
)


@pytest.fixture
def pdf_file():
with open("tests/data/empty.pdf", "rb") as pdf:
Expand Down
Loading