[Django] #27209: Cast function accepts field class according to docs but expects field instance

14 views
Skip to first unread message

Django

unread,
Sep 11, 2016, 2:31:19 PM9/11/16
to django-...@googlegroups.com
#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.

Django

unread,
Sep 11, 2016, 9:48:51 PM9/11/16
to django-...@googlegroups.com
#27209: Cast function accepts field class according to docs but expects field
instance
-------------------------------------+-------------------------------------
Reporter: valentjedi | Owner: charettes
Type: | Status: assigned
Cleanup/optimization |
Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by charettes):

* status: new => assigned
* needs_better_patch: => 0
* component: Database layer (models, ORM) => Documentation
* needs_tests: => 0
* version: 1.10 => master
* owner: nobody => charettes
* needs_docs: => 0
* type: Bug => Cleanup/optimization
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/27209#comment:1>

Django

unread,
Sep 11, 2016, 9:53:47 PM9/11/16
to django-...@googlegroups.com
#27209: Cast function accepts field class according to docs but expects field
instance
-------------------------------------+-------------------------------------
Reporter: valentjedi | Owner: charettes
Type: | Status: assigned
Cleanup/optimization |
Component: Documentation | Version: master
Severity: Normal | 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 charettes):

Here's a [https://github.com/django/django/pull/7234 PR] with the
documentation adjustments.

--
Ticket URL: <https://code.djangoproject.com/ticket/27209#comment:2>

Django

unread,
Sep 11, 2016, 9:53:48 PM9/11/16
to django-...@googlegroups.com
#27209: Cast function accepts field class according to docs but expects field
instance
-------------------------------------+-------------------------------------
Reporter: valentjedi | Owner: charettes
Type: | Status: assigned
Cleanup/optimization |
Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by charettes):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/27209#comment:3>

Django

unread,
Sep 12, 2016, 8:07:47 AM9/12/16
to django-...@googlegroups.com
#27209: Cast function accepts field class according to docs but expects field
instance
-------------------------------------+-------------------------------------
Reporter: valentjedi | Owner: charettes
Type: | Status: closed

Cleanup/optimization |
Component: Documentation | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"767ba009764c6640b20ea6a6dc6ee2559cc87800" 767ba009]:
{{{
#!CommitTicketReference repository=""
revision="767ba009764c6640b20ea6a6dc6ee2559cc87800"
Fixed #27209 -- Fixed typo in docs/ref/models/database-functions.txt.

Thanks Valentin Ignatyev for the report.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27209#comment:4>

Django

unread,
Sep 12, 2016, 8:08:02 AM9/12/16
to django-...@googlegroups.com
#27209: Cast function accepts field class according to docs but expects field
instance
-------------------------------------+-------------------------------------
Reporter: valentjedi | Owner: charettes
Type: | Status: closed
Cleanup/optimization |
Component: Documentation | Version: master
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"23cf7e50d1dfceb0836032d0e8fcf1fa4da7e855" 23cf7e5]:
{{{
#!CommitTicketReference repository=""
revision="23cf7e50d1dfceb0836032d0e8fcf1fa4da7e855"
[1.10.x] Fixed #27209 -- Fixed typo in docs/ref/models/database-
functions.txt.

Thanks Valentin Ignatyev for the report.

Backport of 767ba009764c6640b20ea6a6dc6ee2559cc87800 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27209#comment:5>

Reply all
Reply to author
Forward
0 new messages