﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
27209	Cast function accepts field class according to docs but expects field instance	Valentin Ignatyev	Simon Charette	"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)
}}}"	Cleanup/optimization	closed	Documentation	dev	Normal	fixed			Accepted	1	0	0	0	0	0
