Skip to content

Commit

Permalink
Fixed #36148 -- Enabled native tuple comparison lookups on SQLite 3.3…
Browse files Browse the repository at this point in the history
…7+ and Oracle 23.4+.

VALUES must be explicitly specified when declaring a sequence of tuples
on SQLite < 3.37 but it's not required on >= 3.37.

See sqlite/sqlite@9289f51 which addressed the last remaining issue with
IN.
  • Loading branch information
charettes authored and felixxm committed Feb 9, 2025
1 parent a0a765d commit 4a3ad9e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
6 changes: 5 additions & 1 deletion django/db/backends/oracle/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
allows_multiple_constraints_on_same_fields = False
supports_json_field_contains = False
supports_collation_on_textfield = False
supports_tuple_lookups = False
test_now_utc_template = "CURRENT_TIMESTAMP AT TIME ZONE 'UTC'"
django_test_expected_failures = {
# A bug in Django/oracledb with respect to string handling (#23843).
Expand Down Expand Up @@ -217,3 +216,8 @@ def supports_aggregation_over_interval_types(self):
@cached_property
def bare_select_suffix(self):
return "" if self.connection.oracle_version >= (23,) else " FROM DUAL"

@cached_property
def supports_tuple_lookups(self):
# Support is known to be missing on 23.2 but available on 23.4.
return self.connection.oracle_version >= (23, 4)
1 change: 0 additions & 1 deletion django/db/backends/sqlite3/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
insert_test_table_with_defaults = 'INSERT INTO {} ("null") VALUES (1)'
supports_default_keyword_in_insert = False
supports_unlimited_charfield = True
supports_tuple_lookups = False

@cached_property
def django_test_skips(self):
Expand Down
11 changes: 11 additions & 0 deletions django/db/models/fields/tuple_lookups.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ def __len__(self):
def __iter__(self):
return iter(self.source_expressions)

def as_sqlite(self, compiler, connection):
if connection.get_database_version() < (3, 37) and isinstance(
first_expr := self.source_expressions[0], Tuple
):
first_expr = first_expr.copy()
first_expr.function = "VALUES"
return Tuple(first_expr, *self.source_expressions[1:]).as_sql(
compiler, connection
)
return self.as_sql(compiler, connection)


class TupleLookupMixin:
allows_composite_expressions = True
Expand Down

0 comments on commit 4a3ad9e

Please sign in to comment.