diff options
| author | Clifford Gama <cliffygamy@gmail.com> | 2025-06-12 09:35:07 +0200 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2025-06-16 10:40:29 +0200 |
| commit | 104cbfd44b9eff010daf0ef0e1ce434385855b13 (patch) | |
| tree | f0d975b1a8e065cb5d0d5c425ba42cd1763e5711 /django | |
| parent | 12c1557060fc94fe5e1fbddc4578a4e29d38f77c (diff) | |
Fixed #36453 -- Made When.condition resolve with for_save=False.
Value(None, JSONField()) when used in When.condition incorrectly resolved with
for_save=True, resulting in the value being serialized as SQL NULL instead of
JSON null.
Regression in c1fa3fdd040718356e5a3b9a0fe699d73f47a940.
Thanks to Thomas McKay for the report, and to David Sanders and Simon Charettes
for the review.
Co-authored-by: Sarah Boyce <42296566+sarahboyce@users.noreply.github.com>
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/models/expressions.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/django/db/models/expressions.py b/django/db/models/expressions.py index dc070114c9..bf89a4f561 100644 --- a/django/db/models/expressions.py +++ b/django/db/models/expressions.py @@ -1620,6 +1620,17 @@ class When(Expression): def set_source_expressions(self, exprs): self.condition, self.result = exprs + def resolve_expression( + self, query=None, allow_joins=True, reuse=None, summarize=False, for_save=False + ): + c = super().resolve_expression(query, allow_joins, reuse, summarize, for_save) + if for_save and c.condition is not None: + # Resolve condition with for_save=False, since it's used as a filter. + c.condition = self.condition.resolve_expression( + query, allow_joins, reuse, summarize, for_save=False + ) + return c + def get_source_fields(self): # We're only interested in the fields of the result expressions. return [self.result._output_field_or_none] |
