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 | |
| 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')
| -rw-r--r-- | django/db/models/sql/compiler.py | 19 | ||||
| -rw-r--r-- | django/db/models/sql/datastructures.py | 7 | ||||
| -rw-r--r-- | django/db/models/sql/query.py | 57 | ||||
| -rw-r--r-- | django/db/models/sql/subqueries.py | 6 |
4 files changed, 49 insertions, 40 deletions
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index b0b2ac5583..f72ba907ad 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -52,10 +52,11 @@ class SQLCompiler: # they would return an empty result set. self.elide_empty = elide_empty self.quote_cache = {"*": "*"} - # The select, klass_info, and annotations are needed by QuerySet.iterator() - # these are set as a side-effect of executing the query. Note that we calculate - # separately a list of extra select columns needed for grammatical correctness - # of the query, but these columns are not included in self.select. + # The select, klass_info, and annotations are needed by + # QuerySet.iterator() these are set as a side-effect of executing the + # query. Note that we calculate separately a list of extra select + # columns needed for grammatical correctness of the query, but these + # columns are not included in self.select. self.select = None self.annotation_col_map = None self.klass_info = None @@ -946,9 +947,9 @@ class SQLCompiler: # If the query is used as a subquery, the extra selects would # result in more columns than the left-hand side expression is # expecting. This can happen when a subquery uses a combination - # of order_by() and distinct(), forcing the ordering expressions - # to be selected as well. Wrap the query in another subquery - # to exclude extraneous selects. + # of order_by() and distinct(), forcing the ordering + # expressions to be selected as well. Wrap the query in another + # subquery to exclude extraneous selects. sub_selects = [] sub_params = [] for index, (select, _, alias) in enumerate(self.select, start=1): @@ -2107,8 +2108,8 @@ class SQLUpdateCompiler(SQLCompiler): # If the result_type is NO_RESULTS then the aux_row_count is None. aux_row_count = query.get_compiler(self.using).execute_sql(result_type) if is_empty and aux_row_count: - # Returns the row count for any related updates as the number of - # rows updated. + # Returns the row count for any related updates as the number + # of rows updated. row_count = aux_row_count is_empty = False return row_count diff --git a/django/db/models/sql/datastructures.py b/django/db/models/sql/datastructures.py index be6934485c..ffdd36c0c8 100644 --- a/django/db/models/sql/datastructures.py +++ b/django/db/models/sql/datastructures.py @@ -37,8 +37,8 @@ class Join: - table_alias (possible alias for the table, can be None) - join_type (can be None for those entries that aren't joined from anything) - - parent_alias (which table is this join's parent, can be None similarly - to join_type) + - parent_alias (which table is this join's parent, can be None + similarly to join_type) - as_sql() - relabeled_clone() """ @@ -76,7 +76,8 @@ class Join: def as_sql(self, compiler, connection): """ Generate the full - LEFT OUTER JOIN sometable ON sometable.somecol = othertable.othercol, params + LEFT OUTER JOIN sometable ON sometable.somecol = + othertable.othercol, params clause for this join. """ join_conditions = [] 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 diff --git a/django/db/models/sql/subqueries.py b/django/db/models/sql/subqueries.py index 9cb971b38f..2705114a54 100644 --- a/django/db/models/sql/subqueries.py +++ b/django/db/models/sql/subqueries.py @@ -1,5 +1,6 @@ """ -Query subclasses which provide extra functionality beyond simple data retrieval. +Query subclasses which provide extra functionality beyond simple data +retrieval. """ from django.core.exceptions import FieldError @@ -116,7 +117,8 @@ class UpdateQuery(Query): if field.generated: continue if hasattr(val, "resolve_expression"): - # Resolve expressions here so that annotations are no longer needed + # Resolve expressions here so that annotations are no longer + # needed val = val.resolve_expression(self, allow_joins=False, for_save=True) self.values.append((field, model, val)) |
