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/postgresql/operations.py | |
parent | 594fcc2b7427f7baf2cf1a2d7cd2be61467df0c3 (diff) | |
download | django-9bbf97bcdb488bb11aebb5bd405549fbec6852cd.tar.gz |
Fixed #16055 -- Fixed crash when filtering against char/text GenericRelation relation on PostgreSQL.
Diffstat (limited to 'django/db/backends/postgresql/operations.py')
-rw-r--r-- | django/db/backends/postgresql/operations.py | 11 |
1 files changed, 11 insertions, 0 deletions
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 |