Skip to content

Commit 18080ca

Browse files
committed
Remove SubqueryConstraint and other multi-column FK orphans
Follow-up cleanup after removing MultiColSource. All of these only existed to support multi-column FK joins which aren't possible in plain-postgres: - SubqueryConstraint (sql/where.py) — only instantiated by the deleted MultiColSource branch in RelatedIn.as_sql - SQLCompiler.as_subquery_condition — only caller was SubqueryConstraint - Unreachable `len(targets) > 1` FieldError raise in build_filter's F() handling (sql/query.py) - Unreachable `len(target_fields) > 1` FieldError raise in ForeignObjectRel.target_field (reverse_related.py)
1 parent 9d4ff49 commit 18080ca

4 files changed

Lines changed: 1 addition & 48 deletions

File tree

plain-postgres/plain/postgres/fields/reverse_related.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from functools import cached_property
1515
from typing import TYPE_CHECKING, Any
1616

17-
from plain.postgres.exceptions import FieldError
1817
from plain.utils.hashable import make_hashable
1918

2019
from . import BLANK_CHOICE_DASH
@@ -94,10 +93,7 @@ def target_field(self) -> Field:
9493
When filtering against this relation, return the field on the remote
9594
model against which the filtering should happen.
9695
"""
97-
target_fields = self.path_infos[-1].target_fields
98-
if len(target_fields) > 1:
99-
raise FieldError("Can't use target_field for multicolumn relations.")
100-
return target_fields[0]
96+
return self.path_infos[-1].target_fields[0]
10197

10298
@cached_property
10399
def related_model(self) -> type[Model]:

plain-postgres/plain/postgres/sql/compiler.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
SINGLE,
4444
)
4545
from plain.postgres.sql.query import Query, get_order_dir
46-
from plain.postgres.sql.where import AND
4746
from plain.postgres.transaction import TransactionManagementError
4847
from plain.utils.hashable import make_hashable
4948
from plain.utils.regex_helper import _lazy_re_compile
@@ -1426,20 +1425,6 @@ def execute_sql(
14261425
rows = [r[: self.col_count] for r in rows]
14271426
return rows
14281427

1429-
def as_subquery_condition(
1430-
self, alias: str, columns: list[str], compiler: SQLCompiler
1431-
) -> SqlWithParams:
1432-
qn = compiler.quote_name_unless_alias
1433-
qn2 = quote_name
1434-
1435-
for index, select_col in enumerate(self.query.select):
1436-
lhs_sql, lhs_params = self.compile(select_col)
1437-
rhs = f"{qn(alias)}.{qn2(columns[index])}"
1438-
self.query.where.add(RawSQL(f"{lhs_sql} = {rhs}", lhs_params), AND)
1439-
1440-
sql, params = self.as_sql()
1441-
return f"EXISTS ({sql})", params
1442-
14431428
def explain_query(self) -> Generator[str]:
14441429
result = self.execute_sql()
14451430
explain_info = self.query.explain_info

plain-postgres/plain/postgres/sql/query.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1996,10 +1996,6 @@ def resolve_ref(
19961996
raise FieldError(
19971997
"Joined field references are not permitted in this query"
19981998
)
1999-
if len(targets) > 1:
2000-
raise FieldError(
2001-
"Referencing multicolumn fields with F() objects isn't supported"
2002-
)
20031999
# Verify that the last lookup in name is a field or a transform:
20042000
# transform_function() raises FieldError if not.
20052001
transform = join_info.transform_function(targets[0], final_alias)

plain-postgres/plain/postgres/sql/where.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -348,27 +348,3 @@ def as_sql(
348348
) -> tuple[str, list[Any]]:
349349
sqls = [f"({sql})" for sql in self.sqls]
350350
return " AND ".join(sqls), list(self.params or ())
351-
352-
353-
class SubqueryConstraint:
354-
# Even if aggregates or windows would be used in a subquery,
355-
# the outer query isn't interested about those.
356-
contains_aggregate = False
357-
contains_over_clause = False
358-
359-
def __init__(
360-
self, alias: str, columns: list[str], targets: list[Any], query_object: Any
361-
):
362-
self.alias = alias
363-
self.columns = columns
364-
self.targets = targets
365-
query_object.clear_ordering(clear_default=True)
366-
self.query_object = query_object
367-
368-
def as_sql(
369-
self, compiler: SQLCompiler, connection: DatabaseConnection
370-
) -> tuple[str, list[Any]]:
371-
query = self.query_object
372-
query.set_values(self.targets)
373-
query_compiler = query.get_compiler()
374-
return query_compiler.as_subquery_condition(self.alias, self.columns, compiler)

0 commit comments

Comments
 (0)