Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-mm committed Oct 16, 2023
2 parents 80415e0 + f6629ee commit 010e248
Show file tree
Hide file tree
Showing 8 changed files with 204 additions and 142 deletions.
7 changes: 7 additions & 0 deletions django/db/models/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,13 @@ def contains_column_references(self):
for expr in self.get_source_expressions()
)

@cached_property
def contains_subquery(self):
return any(
expr and (getattr(expr, "subquery", False) or expr.contains_subquery)
for expr in self.get_source_expressions()
)

def resolve_expression(
self, query=None, allow_joins=True, reuse=None, summarize=False, for_save=False
):
Expand Down
2 changes: 1 addition & 1 deletion django/db/models/sql/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ def get_aggregation(self, using, aggregate_exprs):
# members of `aggregates` to resolve against each others.
self.append_annotation_mask([alias])
refs_subquery |= any(
getattr(self.annotations[ref], "subquery", False)
getattr(self.annotations[ref], "contains_subquery", False)
for ref in aggregate.get_refs()
)
refs_window |= any(
Expand Down
29 changes: 29 additions & 0 deletions django/test/selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,20 @@ def create_webdriver(self):
return self.import_webdriver(self.browser)(options=options)


class ChangeWindowSize:
def __init__(self, width, height, selenium):
self.selenium = selenium
self.new_size = (width, height)

def __enter__(self):
self.old_size = self.selenium.get_window_size()
self.selenium.set_window_size(*self.new_size)
return self

def __exit__(self, exc_type, exc_value, traceback):
self.selenium.set_window_size(self.old_size["width"], self.old_size["height"])


@tag("selenium")
class SeleniumTestCase(LiveServerTestCase, metaclass=SeleniumTestCaseBase):
implicit_wait = 10
Expand All @@ -118,6 +132,21 @@ def setUpClass(cls):
super().setUpClass()
cls.addClassCleanup(cls._quit_selenium)

@contextmanager
def desktop_size(self):
with ChangeWindowSize(1280, 720, self.selenium):
yield

@contextmanager
def small_screen_size(self):
with ChangeWindowSize(1024, 768, self.selenium):
yield

@contextmanager
def mobile_size(self):
with ChangeWindowSize(360, 800, self.selenium):
yield

@classmethod
def _quit_selenium(cls):
# quit() the WebDriver before attempting to terminate and join the
Expand Down
4 changes: 3 additions & 1 deletion docs/releases/4.2.7.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ Django 4.2.7 fixes several bugs in 4.2.6.
Bugfixes
========

...
* Fixed a regression in Django 4.2 that caused a crash of
``QuerySet.aggregate()`` with aggregates referencing expressions containing
subqueries (:ticket:`34798`).
8 changes: 2 additions & 6 deletions tests/admin_views/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6489,14 +6489,10 @@ def test_hidden_fields_small_window(self):
)
self.selenium.get(self.live_server_url + reverse("admin:admin_views_story_add"))
field_title = self.selenium.find_element(By.CLASS_NAME, "field-title")
current_size = self.selenium.get_window_size()
try:
self.selenium.set_window_size(1024, 768)
with self.small_screen_size():
self.assertIs(field_title.is_displayed(), False)
self.selenium.set_window_size(767, 575)
with self.mobile_size():
self.assertIs(field_title.is_displayed(), False)
finally:
self.selenium.set_window_size(current_size["width"], current_size["height"])

def test_updating_related_objects_updates_fk_selects_except_autocompletes(self):
from selenium.webdriver.common.by import By
Expand Down
Loading

0 comments on commit 010e248

Please sign in to comment.