diff options
| author | David Wobrock <david.wobrock@gmail.com> | 2023-04-18 10:19:06 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-04-18 12:41:14 +0200 |
| commit | 9bbf97bcdb488bb11aebb5bd405549fbec6852cd (patch) | |
| tree | d679e1a72227b9b6b5b5f44af6a4e231228f2d0d /django/db/backends | |
| parent | 594fcc2b7427f7baf2cf1a2d7cd2be61467df0c3 (diff) | |
Fixed #16055 -- Fixed crash when filtering against char/text GenericRelation relation on PostgreSQL.
Diffstat (limited to 'django/db/backends')
| -rw-r--r-- | django/db/backends/base/operations.py | 7 | ||||
| -rw-r--r-- | django/db/backends/oracle/features.py | 3 | ||||
| -rw-r--r-- | django/db/backends/postgresql/operations.py | 11 |
3 files changed, 21 insertions, 0 deletions
diff --git a/django/db/backends/base/operations.py b/django/db/backends/base/operations.py index d2bc336dd8..6f10e31cd5 100644 --- a/django/db/backends/base/operations.py +++ b/django/db/backends/base/operations.py @@ -8,6 +8,7 @@ import sqlparse from django.conf import settings from django.db import NotSupportedError, transaction from django.db.backends import utils +from django.db.models.expressions import Col from django.utils import timezone from django.utils.encoding import force_str @@ -776,3 +777,9 @@ class BaseDatabaseOperations: def on_conflict_suffix_sql(self, fields, on_conflict, update_fields, unique_fields): return "" + + def prepare_join_on_clause(self, lhs_table, lhs_field, rhs_table, rhs_field): + lhs_expr = Col(lhs_table, lhs_field) + rhs_expr = Col(rhs_table, rhs_field) + + return lhs_expr, rhs_expr diff --git a/django/db/backends/oracle/features.py b/django/db/backends/oracle/features.py index 3d77a615c8..05dc552a98 100644 --- a/django/db/backends/oracle/features.py +++ b/django/db/backends/oracle/features.py @@ -120,6 +120,9 @@ class DatabaseFeatures(BaseDatabaseFeatures): "migrations.test_operations.OperationTests." "test_alter_field_pk_fk_db_collation", }, + "Oracle doesn't support comparing NCLOB to NUMBER.": { + "generic_relations_regress.tests.GenericRelationTests.test_textlink_filter", + }, } django_test_expected_failures = { # A bug in Django/cx_Oracle with respect to string handling (#23843). diff --git a/django/db/backends/postgresql/operations.py b/django/db/backends/postgresql/operations.py index 18cfcb29cb..aa839f5634 100644 --- a/django/db/backends/postgresql/operations.py +++ b/django/db/backends/postgresql/operations.py @@ -12,6 +12,7 @@ from django.db.backends.postgresql.psycopg_any import ( ) from django.db.backends.utils import split_tzname_delta from django.db.models.constants import OnConflict +from django.db.models.functions import Cast from django.utils.regex_helper import _lazy_re_compile @@ -413,3 +414,13 @@ class DatabaseOperations(BaseDatabaseOperations): update_fields, unique_fields, ) + + def prepare_join_on_clause(self, lhs_table, lhs_field, rhs_table, rhs_field): + lhs_expr, rhs_expr = super().prepare_join_on_clause( + lhs_table, lhs_field, rhs_table, rhs_field + ) + + if lhs_field.db_type(self.connection) != rhs_field.db_type(self.connection): + rhs_expr = Cast(rhs_expr, lhs_field) + + return lhs_expr, rhs_expr |
