[Django] #28408: Inconsistant error message for trying to update an annotated F expression

37 views
Skip to first unread message

Django

unread,
Jul 18, 2017, 4:14:00 AM7/18/17
to django-...@googlegroups.com
#28408: Inconsistant error message for trying to update an annotated F expression
-------------------------------------+-------------------------------------
Reporter: Kevin | Owner: (none)
Marsh |
Type: | Status: new
Uncategorized |
Component: Error | Version: 1.11
reporting |
Severity: Normal | Keywords: annotate, F, update
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
I ran into a bit of a nasty error yesterday on Django 1.11, Postgres 9.5
where I was trying to do an update using an `F` expression where the value
in that expression referred to an annotation of an annotation, each using
a `Case` statement inside the annotation. The error message it was giving
me was something like the following:


{{{
ProgrammingError Traceback (most recent call
last)
<ipython-input-1-29e48364245c> in <module>()
----> 1 MyModel.objects.causing_problems()

/usr/src/app/apps/myapp/managers.py in causing_problems(self)
833 ).update(
--> 834 my_field=F('my_annotated_field'),
835 )
836

/usr/src/app/apps/django/db/models/query.py in update(self, **kwargs)
645 query._annotations = None
646 with transaction.atomic(using=self.db, savepoint=False):
--> 647 rows = query.get_compiler(self.db).execute_sql(CURSOR)
648 self._result_cache = None
649 return rows

/usr/src/app/apps/django/db/models/sql/compiler.py in execute_sql(self,
result_type)
1189 related queries are not available.
1190 """
-> 1191 cursor = super(SQLUpdateCompiler,
self).execute_sql(result_type)
1192 try:
1193 rows = cursor.rowcount if cursor else 0

/usr/src/app/apps/django/db/models/sql/compiler.py in execute_sql(self,
result_type, chunked_fetch)
884 # silencing when dropping Python 2 compatibility.
885 pass
--> 886 raise original_exception
887
888 if result_type == CURSOR:

ProgrammingError: missing FROM-clause entry for table "myapp_mymodel"
LINE 1: ...false END, "a_field" = CASE WHEN CASE WHEN ("myapp_my...
}}}

Spent a while trying to debug where it was going wrong, ended up narrowing
down the problem to trying to update a field using an `F` expression on an
annotated field which included a join in it. I'm not sure if better error
message would have helped in my case but in the much simpler test attached
it'd be usfeul if the first and second assertions raised the same or
similar error message.

--
Ticket URL: <https://code.djangoproject.com/ticket/28408>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 18, 2017, 4:14:46 AM7/18/17
to django-...@googlegroups.com
#28408: Inconsistant error message for trying to update an annotated F expression
-------------------------------------+-------------------------------------
Reporter: Kevin Marsh | Owner: (none)
Type: Uncategorized | Status: new
Component: Error reporting | Version: 1.11
Severity: Normal | Resolution:

Keywords: annotate, F, update | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Kevin Marsh):

* Attachment "unclear_f_annotations_error_message_failing_test.diff"
added.

Django

unread,
Jul 18, 2017, 8:08:11 AM7/18/17
to django-...@googlegroups.com
#28408: Incorrect error message with QuerySet.update() that requires a join on an
annotated F expression
-------------------------------------+-------------------------------------
Reporter: Kevin Marsh | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution:
Keywords: annotate, F, update | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* owner: (none) => nobody
* type: Uncategorized => Bug
* component: Error reporting => Database layer (models, ORM)
* stage: Unreviewed => Accepted


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

Django

unread,
Mar 26, 2019, 2:18:36 PM3/26/19
to django-...@googlegroups.com
#28408: Incorrect error message with QuerySet.update() that requires a join on an
annotated F expression
-------------------------------------+-------------------------------------

Reporter: Kevin Marsh | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution:
Keywords: annotate, F, update | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Can Sarıgöl):

hi, I tried to fix on version 2.
[https://github.com/django/django/pull/11129 PR]

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

Django

unread,
Mar 26, 2019, 2:19:29 PM3/26/19
to django-...@googlegroups.com
#28408: Incorrect error message with QuerySet.update() that requires a join on an
annotated F expression
-------------------------------------+-------------------------------------

Reporter: Kevin Marsh | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution:
Keywords: annotate, F, update | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Can Sarıgöl):

* cc: Can Sarıgöl (added)


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

Django

unread,
Mar 26, 2019, 3:25:28 PM3/26/19
to django-...@googlegroups.com
#28408: Incorrect error message with QuerySet.update() that requires a join on an
annotated F expression
-------------------------------------+-------------------------------------

Reporter: Kevin Marsh | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution:
Keywords: annotate, F, update | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Can Sarıgöl):

* has_patch: 0 => 1


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

Django

unread,
Apr 1, 2019, 3:39:06 AM4/1/19
to django-...@googlegroups.com
#28408: Incorrect error message with QuerySet.update() that requires a join on an
annotated F expression
-------------------------------------+-------------------------------------

Reporter: Kevin Marsh | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: master

(models, ORM) |
Severity: Normal | Resolution:
Keywords: annotate, F, update | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Asif Saifuddin Auvi):

* needs_docs: 0 => 1
* version: 1.11 => master


Old description:

New description:

it'd be useful if the first and second assertions raised the same or
similar error message.

--

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

Django

unread,
Apr 16, 2019, 2:26:12 AM4/16/19
to django-...@googlegroups.com
#28408: Incorrect error message with QuerySet.update() that requires a join on an
annotated F expression
-------------------------------------+-------------------------------------
Reporter: Kevin Marsh | Owner: Can
| Sarıgöl
Type: Bug | Status: assigned

Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: annotate, F, update | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Can Sarıgöl):

* owner: nobody => Can Sarıgöl
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/28408#comment:6>

Django

unread,
Apr 25, 2019, 3:38:50 AM4/25/19
to django-...@googlegroups.com
#28408: Incorrect error message with QuerySet.update() that requires a join on an
annotated F expression
-------------------------------------+-------------------------------------

Reporter: Kevin Marsh | Owner: Can
| Sarıgöl
Type: Bug | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: annotate, F, update | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Asif Saifuddin Auvi):

* needs_docs: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/28408#comment:7>

Django

unread,
Jun 21, 2019, 6:11:24 AM6/21/19
to django-...@googlegroups.com
#28408: Incorrect error message with QuerySet.update() that requires a join on an
annotated F expression
-------------------------------------+-------------------------------------

Reporter: Kevin Marsh | Owner: Can
| Sarıgöl
Type: Bug | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: annotate, F, update | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

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

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/28408#comment:8>

Django

unread,
Jun 21, 2019, 10:20:09 AM6/21/19
to django-...@googlegroups.com
#28408: Incorrect error message with QuerySet.update() that requires a join on an
annotated F expression
-------------------------------------+-------------------------------------

Reporter: Kevin Marsh | Owner: Can
| Sarıgöl
Type: Bug | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: annotate, F, update | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Can Sarıgöl):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/28408#comment:9>

Django

unread,
Jun 28, 2019, 1:25:06 AM6/28/19
to django-...@googlegroups.com
#28408: Incorrect error message with QuerySet.update() that requires a join on an
annotated F expression
-------------------------------------+-------------------------------------

Reporter: Kevin Marsh | Owner: Can
| Sarıgöl
Type: Bug | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: annotate, F, update | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by felixxm):

Original ticket #26539.

--
Ticket URL: <https://code.djangoproject.com/ticket/28408#comment:10>

Django

unread,
Jun 28, 2019, 3:42:27 AM6/28/19
to django-...@googlegroups.com
#28408: Incorrect error message with QuerySet.update() that requires a join on an
annotated F expression
-------------------------------------+-------------------------------------

Reporter: Kevin Marsh | Owner: Can
| Sarıgöl
Type: Bug | Status: closed

Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: annotate, F, update | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

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


Comment:

In [changeset:"f03b7bd11461e8b525c27d5344f8cd3a21c9565e" f03b7bd1]:
{{{
#!CommitTicketReference repository=""
revision="f03b7bd11461e8b525c27d5344f8cd3a21c9565e"
Fixed #28408 -- Added error message when updating with annotated
expressions on joined fields.

Co-Authored-By: Simon Charette <chare...@gmail.com>
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28408#comment:11>

Reply all
Reply to author
Forward
0 new messages