diff options
| author | Jacob Walls <jacobtylerwalls@gmail.com> | 2024-12-31 13:10:35 -0500 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2025-01-07 11:42:06 +0100 |
| commit | 6eec703667505d87d1354323548943c8d546c5a2 (patch) | |
| tree | 73a6a57401b9f4ad9f158b12aee106a2008df0a8 /django | |
| parent | 8914b571eb5f93722b9741b1da9eb69347271b11 (diff) | |
Fixed #36042 -- Raised ValueError when using CompositePrimaryKey as rhs.
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/models/expressions.py | 2 | ||||
| -rw-r--r-- | django/db/models/lookups.py | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/django/db/models/expressions.py b/django/db/models/expressions.py index 667e9f93c6..88c5596c17 100644 --- a/django/db/models/expressions.py +++ b/django/db/models/expressions.py @@ -758,6 +758,8 @@ class CombinedExpression(SQLiteNumericMixin, Expression): rhs = self.rhs.resolve_expression( query, allow_joins, reuse, summarize, for_save ) + if isinstance(lhs, ColPairs) or isinstance(rhs, ColPairs): + raise ValueError("CompositePrimaryKey is not combinable.") if not isinstance(self, (DurationExpression, TemporalSubtraction)): try: lhs_type = lhs.output_field.get_internal_type() diff --git a/django/db/models/lookups.py b/django/db/models/lookups.py index 734f911f83..56dbdabac1 100644 --- a/django/db/models/lookups.py +++ b/django/db/models/lookups.py @@ -4,7 +4,7 @@ import warnings from django.core.exceptions import EmptyResultSet, FullResultSet from django.db.backends.base.operations import BaseDatabaseOperations -from django.db.models.expressions import Case, Expression, Func, Value, When +from django.db.models.expressions import Case, ColPairs, Expression, Func, Value, When from django.db.models.fields import ( BooleanField, CharField, @@ -119,6 +119,10 @@ class Lookup(Expression): value = value.resolve_expression(compiler.query) if hasattr(value, "as_sql"): sql, params = compiler.compile(value) + if isinstance(value, ColPairs): + raise ValueError( + "CompositePrimaryKey cannot be used as a lookup value." + ) # Ensure expression is wrapped in parentheses to respect operator # precedence but avoid double wrapping as it can be misinterpreted # on some backends (e.g. subqueries on SQLite). |
