#34160: Django 4.1 Expression contains mixed types for (Big/Small)IntegerFields.
-------------------------------------+-------------------------------------
Reporter: Martin Lehoux | Owner: Martin
| Lehoux
Type: Bug | Status: assigned
Component: Database layer | Version: 4.1
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Mariusz Felisiak):
`Case()` is trying to resolve an output type only for specific fields that
cannot be implicitly cast on PostgreSQL (namely `GenericIPAddressField`,
`IPAddressField`, `TimeField`, and `UUIDField`) in other cases PostgreSQL
does the work, see [https://www.postgresql.org/docs/current/typeconv-
union-case.html docs]. As far as I'm aware, we should be safe to ignore
errors in resolving an output field in other cases:
{{{#!diff
diff --git a/django/db/models/expressions.py
b/django/db/models/expressions.py
index c270ef16c7..575712806f 100644
--- a/django/db/models/expressions.py
+++ b/django/db/models/expressions.py
@@ -1483,8 +1483,11 @@ class Case(SQLiteNumericMixin, Expression):
sql_params.extend(default_params)
template = template or template_params.get("template",
self.template)
sql = template % template_params
- if self._output_field_or_none is not None:
- sql = connection.ops.unification_cast_sql(self.output_field)
% sql
+ try:
+ if self._output_field_or_none is not None:
+ sql =
connection.ops.unification_cast_sql(self.output_field) % sql
+ except FieldError:
+ pass
return sql, sql_params
def get_group_by_cols(self):
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34160#comment:15>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/01070184bd9da48f-428d6a48-324b-4d04-997b-fcfe8e54765e-000000%40eu-central-1.amazonses.com.