diff options
| author | django-bot <ops@djangoproject.com> | 2025-07-22 20:41:41 -0700 |
|---|---|---|
| committer | nessita <124304+nessita@users.noreply.github.com> | 2025-07-23 20:17:55 -0300 |
| commit | 69a93a88edb56ba47f624dac7a21aacc47ea474f (patch) | |
| tree | f57507a4435d032493cae40e06ecb254790b67b2 /django/db/models/sql/query.py | |
| parent | 55b0cc21310b76ce4018dd793ba50556eaf0af06 (diff) | |
Refs #36500 -- Rewrapped long docstrings and block comments via a script.
Rewrapped long docstrings and block comments to 79 characters + newline
using script from https://github.com/medmunds/autofix-w505.
Diffstat (limited to 'django/db/models/sql/query.py')
| -rw-r--r-- | django/db/models/sql/query.py | 57 |
1 files changed, 31 insertions, 26 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 20dbf7cfaa..5e87f65e7c 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -308,10 +308,9 @@ class Query(BaseExpression): self.alias_map = {} # Whether to provide alias to columns during reference resolving. self.alias_cols = alias_cols - # Sometimes the query contains references to aliases in outer queries (as - # a result of split_exclude). Correct alias quoting needs to know these - # aliases too. - # Map external tables to whether they are aliased. + # Sometimes the query contains references to aliases in outer queries + # (as a result of split_exclude). Correct alias quoting needs to know + # these aliases too. Map external tables to whether they are aliased. self.external_aliases = {} self.table_map = {} # Maps table names to list of aliases. self.used_aliases = set() @@ -593,8 +592,8 @@ class Query(BaseExpression): and not inner_query.annotation_select_mask ): # In case of Model.objects[0:3].count(), there would be no - # field selected in the inner query, yet we must use a subquery. - # So, make sure at least one field is selected. + # field selected in the inner query, yet we must use a + # subquery. So, make sure at least one field is selected. inner_query.select = ( self.model._meta.pk.get_col(inner_query.get_initial_alias()), ) @@ -932,10 +931,11 @@ class Query(BaseExpression): an outer join. If 'unconditional' is False, only promote the join if it is nullable or the parent join is an outer join. - The children promotion is done to avoid join chains that contain a LOUTER - b INNER c. So, if we have currently a INNER b INNER c and a->b is promoted, - then we must also promote b->c automatically, or otherwise the promotion - of a->b doesn't actually change anything in the query results. + The children promotion is done to avoid join chains that contain a + LOUTER b INNER c. So, if we have currently a INNER b INNER c and a->b + is promoted, then we must also promote b->c automatically, or otherwise + the promotion of a->b doesn't actually change anything in the query + results. """ aliases = list(aliases) while aliases: @@ -1228,7 +1228,8 @@ class Query(BaseExpression): if FORBIDDEN_ALIAS_PATTERN.search(alias): raise ValueError( "Column aliases cannot contain whitespace characters, quotation marks, " - # RemovedInDjango70Warning: When the deprecation ends, replace with: + # RemovedInDjango70Warning: When the deprecation ends, replace + # with: # "semicolons, percent signs, or SQL comments." "semicolons, or SQL comments." ) @@ -1256,7 +1257,8 @@ class Query(BaseExpression): def resolve_expression(self, query, *args, **kwargs): clone = self.clone() - # Subqueries need to use a different set of aliases than the outer query. + # Subqueries need to use a different set of aliases than the outer + # query. clone.bump_prefix(query) clone.subquery = True clone.where.resolve_expression(query, *args, **kwargs) @@ -1893,9 +1895,9 @@ class Query(BaseExpression): Return the final field involved in the joins, the target field (used for any 'where' constraint), the final 'opts' value, the joins, the field path traveled to generate the joins, and a transform function - that takes a field and alias and is equivalent to `field.get_col(alias)` - in the simple case but wraps field transforms if they were included in - names. + that takes a field and alias and is equivalent to + `field.get_col(alias)` in the simple case but wraps field transforms if + they were included in names. The target field is the field containing the concrete value. Final field can be something different, for example foreign key pointing to @@ -2052,7 +2054,8 @@ class Query(BaseExpression): # Summarize currently means we are doing an aggregate() query # which is executed as a wrapped subquery if any of the # aggregate() elements reference an existing annotation. In - # that case we need to return a Ref to the subquery's annotation. + # that case we need to return a Ref to the subquery's + # annotation. if name not in self.annotation_select: raise FieldError( "Cannot aggregate over the '%s' alias. Use annotate() " @@ -2127,8 +2130,8 @@ class Query(BaseExpression): alias = col.alias if alias in can_reuse: pk = select_field.model._meta.pk - # Need to add a restriction so that outer query's filters are in effect for - # the subquery, too. + # Need to add a restriction so that outer query's filters are in + # effect for the subquery, too. query.bump_prefix(self) lookup_class = select_field.get_lookup("exact") # Note that the query.select[0].alias is different from alias @@ -2204,7 +2207,8 @@ class Query(BaseExpression): """ Return True if adding filters to this instance is still possible. - Typically, this means no limits or offsets have been put on the results. + Typically, this means no limits or offsets have been put on the + results. """ return not self.is_sliced @@ -2440,8 +2444,8 @@ class Query(BaseExpression): """ # Fields on related models are stored in the literal double-underscore # format, so that we can use a set datastructure. We do the foo__bar - # splitting and handling when computing the SQL column names (as part of - # get_columns()). + # splitting and handling when computing the SQL column names (as part + # of get_columns()). existing, defer = self.deferred_loading if defer: # Add to existing deferred names. @@ -2630,8 +2634,8 @@ class Query(BaseExpression): cols in split_exclude(). Return a lookup usable for doing outerq.filter(lookup=self) and a - boolean indicating if the joins in the prefix contain a LEFT OUTER join. - _""" + boolean indicating if the joins in the prefix contain a LEFT OUTER + join. _""" all_paths = [] for _, paths in names_with_path: all_paths.extend(paths) @@ -2678,9 +2682,10 @@ class Query(BaseExpression): if extra_restriction: self.where.add(extra_restriction, AND) else: - # TODO: It might be possible to trim more joins from the start of the - # inner query if it happens to have a longer join chain containing the - # values in select_fields. Lets punt this one for now. + # TODO: It might be possible to trim more joins from the start of + # the inner query if it happens to have a longer join chain + # containing the values in select_fields. Lets punt this one for + # now. select_fields = [r[1] for r in join_field.related_fields] select_alias = lookup_tables[trimmed_paths] # The found starting point is likely a join_class instead of a |
