#27209: Cast function accepts field class according to docs but expects field
instance
----------------------------------------------+--------------------
Reporter: valentjedi | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: 1.10
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
Example from docs about `django.db.models.functions.Cast` will fail with
`TypeError: db_type() missing 1 required positional argument:
'connection'` because in `as_sql` method when adding db_type to
extra_context we execute db_type method of field class and not field
instance:
{{{
if 'db_type' not in extra_context:
extra_context['db_type'] = self._output_field.db_type(connection)
}}}
Here self._output_field is a class instead of instance. So we either must
pass an instance of field like
{{{
value = Value.objects.annotate(as_float=Cast('integer',
FloatField())).get()
}}}
and point to it in docs or create instance inside `as_sql` like this:
{{{
extra_context['db_type'] = self._output_field().db_type(connection)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27209>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/053.8f03fb821612b2043cf4bee11d1a36e2%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.