From 9bbf97bcdb488bb11aebb5bd405549fbec6852cd Mon Sep 17 00:00:00 2001 From: David Wobrock Date: Tue, 18 Apr 2023 10:19:06 +0200 Subject: Fixed #16055 -- Fixed crash when filtering against char/text GenericRelation relation on PostgreSQL. --- django/db/backends/postgresql/operations.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'django/db/backends/postgresql/operations.py') 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 -- cgit v1.2.1