Skip to content
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
30 changes: 14 additions & 16 deletions src/django_mysql/models/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ def as_sql(
field, field_params = compiler.compile(self.lhs)
value, value_params = compiler.compile(self.rhs)

sql = self.sql_expression % (field, value)
params = tuple(value_params) + tuple(field_params)

return sql, params
return (
self.sql_expression % (field, value),
(*value_params, *field_params),
)


class AppendLeftListF(TwoSidedExpression):
Expand Down Expand Up @@ -148,8 +148,7 @@ def as_sql(
) -> tuple[str, tuple[Any, ...]]:
field, field_params = compiler.compile(self.lhs)

sql = self.sql_expression % (field)
return sql, tuple(field_params)
return (self.sql_expression % (field), field_params)


class PopLeftListF(BaseExpression):
Expand Down Expand Up @@ -180,8 +179,7 @@ def as_sql(
) -> tuple[str, tuple[Any, ...]]:
field, field_params = compiler.compile(self.lhs)

sql = self.sql_expression % (field)
return sql, tuple(field_params)
return (self.sql_expression % (field), field_params)


class SetF:
Expand Down Expand Up @@ -227,10 +225,10 @@ def as_sql(
field, field_params = compiler.compile(self.lhs)
value, value_params = compiler.compile(self.rhs)

sql = self.sql_expression % (value, field)
params = tuple(value_params) + tuple(field_params)

return sql, params
return (
self.sql_expression % (value, field),
(*value_params, *field_params),
)


class RemoveSetF(TwoSidedExpression):
Expand Down Expand Up @@ -280,7 +278,7 @@ def as_sql(
field, field_params = compiler.compile(self.lhs)
value, value_params = compiler.compile(self.rhs)

sql = self.sql_expression % (value, field)
params = tuple(value_params) + tuple(field_params)

return sql, params
return (
self.sql_expression % (value, field),
(*value_params, *field_params),
)
2 changes: 1 addition & 1 deletion src/django_mysql/models/fields/dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def as_sql(
lhs, params = compiler.compile(self.lhs)
return (
f"COLUMN_GET({lhs}, %s AS {self.data_type})",
tuple(params) + (self.key_name,),
(*params, self.key_name),
)


Expand Down
10 changes: 6 additions & 4 deletions src/django_mysql/models/fields/lists.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from collections.abc import Callable, Iterable
from collections.abc import Callable
from typing import Any, cast

from django.core import checks
Expand Down Expand Up @@ -216,12 +216,14 @@ def __init__(self, index: int, *args: Any, **kwargs: Any) -> None:

def as_sql(
self, qn: Callable[[str], str], connection: BaseDatabaseWrapper
) -> tuple[str, Iterable[Any]]:
) -> tuple[str, tuple[Any, ...]]:
lhs, lhs_params = self.process_lhs(qn, connection)
rhs, rhs_params = self.process_rhs(qn, connection)
params = tuple(lhs_params) + tuple(rhs_params)
# Put rhs on the left since that's the order FIND_IN_SET uses
return f"(FIND_IN_SET({rhs}, {lhs}) = {self.index})", params
return (
f"(FIND_IN_SET({rhs}, {lhs}) = {self.index})",
(*lhs_params, *rhs_params),
)


class IndexLookupFactory:
Expand Down
28 changes: 17 additions & 11 deletions src/django_mysql/models/lookups.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from collections.abc import Callable, Iterable
from collections.abc import Callable
from typing import Any

from django.db.backends.base.base import BaseDatabaseWrapper
Expand All @@ -23,11 +23,13 @@ def as_sql(
self,
qn: Callable[[str], str],
connection: BaseDatabaseWrapper,
) -> tuple[str, Iterable[Any]]:
) -> tuple[str, tuple[Any, ...]]:
lhs, lhs_params = self.process_lhs(qn, connection)
rhs, rhs_params = self.process_rhs(qn, connection)
params = tuple(lhs_params) + tuple(rhs_params)
return f"{lhs} SOUNDS LIKE {rhs}", params
return (
f"{lhs} SOUNDS LIKE {rhs}",
(*lhs_params, *rhs_params),
)


class Soundex(Transform):
Expand All @@ -36,7 +38,7 @@ class Soundex(Transform):

def as_sql(
self, compiler: SQLCompiler, connection: BaseDatabaseWrapper
) -> tuple[str, Iterable[Any]]:
) -> tuple[str, tuple[Any, ...]]:
lhs, params = compiler.compile(self.lhs)
return f"SOUNDEX({lhs})", params

Expand All @@ -62,12 +64,14 @@ def get_prep_lookup(self) -> Any:

def as_sql(
self, qn: Callable[[str], str], connection: BaseDatabaseWrapper
) -> tuple[str, Iterable[Any]]:
) -> tuple[str, tuple[Any, ...]]:
lhs, lhs_params = self.process_lhs(qn, connection)
rhs, rhs_params = self.process_rhs(qn, connection)
# Put rhs (and params) on the left since that's the order FIND_IN_SET uses
params = tuple(rhs_params) + tuple(lhs_params)
return f"FIND_IN_SET({rhs}, {lhs})", params
return (
f"FIND_IN_SET({rhs}, {lhs})",
(*rhs_params, *lhs_params),
)


class SetIContains(SetContains):
Expand All @@ -82,8 +86,10 @@ class DynColHasKey(Lookup):

def as_sql(
self, qn: Callable[[str], str], connection: BaseDatabaseWrapper
) -> tuple[str, Iterable[Any]]:
) -> tuple[str, tuple[Any, ...]]:
lhs, lhs_params = self.process_lhs(qn, connection)
rhs, rhs_params = self.process_rhs(qn, connection)
params = tuple(lhs_params) + tuple(rhs_params)
return f"COLUMN_EXISTS({lhs}, {rhs})", params
return (
f"COLUMN_EXISTS({lhs}, {rhs})",
(*lhs_params, *rhs_params),
)
3 changes: 1 addition & 2 deletions src/django_mysql/models/transforms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

from collections.abc import Iterable
from typing import Any

from django.db.backends.base.base import BaseDatabaseWrapper
Expand All @@ -25,6 +24,6 @@ class SetLength(Transform):

def as_sql(
self, compiler: SQLCompiler, connection: BaseDatabaseWrapper
) -> tuple[str, Iterable[Any]]:
) -> tuple[str, tuple[Any, ...]]:
lhs, params = compiler.compile(self.lhs)
return self.expr % (lhs, lhs, lhs), params
2 changes: 1 addition & 1 deletion tests/testapp/test_dynamicfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class DumbTransform(Transform):

def as_sql(self, compiler, connection):
lhs, params = compiler.compile(self.lhs)
return "%s", ["dumb"]
return "%s", ("dumb",)


DynamicField.register_lookup(DumbTransform)
Expand Down